indexOf for Array in AS2

is there an alternative to indexOf to use for arrays in as2?
Who is Participating?
blue-genieConnect With a Mentor Commented:
what exactly are you trying to achieve?
use a for loop to loop through your item arrays convert each item to a String and use the indexOf for the String.

CyanBlueConnect With a Mentor Commented:
No...  indexOf() is not supported in AS2...  But you can create your own if you really want to...  Of course this code won't cover all the possibility, but you could expand from this...

Array.prototype.indexOf = function (element)
	var _len:Number = this.length;
	for (var i:Number = 0 ; i < _len ; i++)
		if (this[i] == element)
			return i;
	return -1;
var arr1:Array = new Array(12, 34, 56, 78, 90);
trace(arr1.indexOf(34));     // 1
var arr2:Array = new Array("Action", "Script", "Hello", "World");
trace(arr2.indexOf("Hello"));     // 2
trace(arr2.indexOf("world"));     // -1

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.