Searching in Array using Array.indexOf() function is very easy . For example,
var toys:Array = new Array();
toys.push(“ball”);
toys.push(“bat”);
toys.push(“glows”);
toys.push(“pads”);
toys.push(23);
toys.push(14);
var searchIndex:int = toys.indexOf(“ball”);
if(searchIndex == -1)
{
trace(“No! how can it be there”);
}
else
{
trace(“Yup! it’s there”); //output will be from here
}
So, it works fine when the value inside the indexed array is primitive – i.e. Number, String, Boolean [...]
Archive for April 21st, 2009
21 Apr
Recent Comments