Actionscript 3.0. Searching an Array for an integar and getting the value's index -


i still new actionscript , need hand something.

i have array filled randomly generated numbers below 6, "order", example, might contain this.

order[1,2,4,2]

i need search integar stored in array. if integar present, add 1 variable "trial" index of value in "order" can clear specific index replacing value value that's outside of random generation range.

so, example, if needed search "2" need code replace first "2" 7 example while leaving second 1 alone , adding 1 value of variable "trial".

i can't think of way this, , attempts @ finding solution online has came 1 thread didn't understand because i'm still quite new actionscript.

check link : array.indexof(item);

which gives index of item in array

var order:array = [1,2,4,2]; //create array order[order.indexof(2)] = 7; //find first position of '2' , replace '7' 

also indexof have optional argument defines start position searching.

indexof(searchelement:*, fromindex:int = 0)

start index jump within same array find target value, example in following snippet, have find index of second '2' in order array :

trace ( order[order.indexof( 2, order.indexof(2)+1 )] ); //outputs '3' 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -