Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1843
  • Last Modified:

indexOf for Array in AS2

is there an alternative to indexOf to use for arrays in as2?
0
jasotasticon
Asked:
jasotasticon
2 Solutions
 
blue-genieCommented:
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.

0
 
CyanBlueCommented:
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...

CyanBlue
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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now