kapkasds kapkasds - 3 years ago 255
ActionScript Question

Actionscript 3 Search for string in array

I have a problem with searching for strings in an array. I want to search for one word and if it exists, I want to trace the position of the string in the array.

I believe it should be something like this:

if (myArray contains "11111111") {
} else {
trace("cant find it");

Answer Source

What kind of syntax are you using there and have you even checked the documentation of the Array class? That should be the first thing you check always, as there is a pretty straightforward method for it:

var arr:Array = ["1111", "2222", "3333"];

trace(arr.indexOf("3333")); //traces the index: 2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download