[Question]How to check an array whether if it consist a value

Here’s an array:

var myArr:Array = new Array(“January”, “February”, “March”, “April”);

if I want to check whether if “February” is presented in myArr, which returns boolean value,
how do I write the code?
I’ve looked into the Flash Help but the array constructer seems don’t have this type of action that fits my need…can anyone help me?:crying:

there is a tutorial on the front page under flash…


var myArr:Array = new Array("January", "February", "March", "April"); 
var searchStr:String = myArr.toString();
index = searchStr.indexOf("February");
trace(index); // if Febuary is not found : output will be: -1 otherwise a positive number

Forgive me if I’m wrong but isn’t that a bit of a buggy search implementation jon? Given an array with the following elements

{“Bob”, “Ethan”, “Paul”}

Your method will return a positive number on a search for ‘B,eth’

Ok so it’s not a likely scenario but it’s still a possibility imagining a user typing in some value and hitting the wrong key

I would go for something more solid such as


function arraySearch(search:String, arr:Array):Boolean {
  for (var i = 0; i < arr.length; i++) {
    if(arr* == search) {
      return true;
    }
  }
 
  return false;
}

Usage


 
if(arraySearch("SomeValue", someArray)) {
 // Do something
}

oh wow~!thanks all~I think i get it!
Actually i forgot that there’s a tutorial on kirupa…thanks for remind, randomagain~