h1

The Good Ol’ indexOf

March 7, 2008

For those of you who might have come from programming in JavaScript, I’m sure indexOf is a pretty handy method when playing around with strings. Flex extends its usage to Arrays too. You can use indexOf in a similar way as you do with strings. In this case, it matches the exact string in all the substrings and returns the substring position in the array.

Usage:


var arr:Array = new Array("apple","mango","orange","banana") ;

var num:uint = arr.indexOf("orange");

trace (num)  //returns 2

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: