# Array control problem

**URL:** <https://forum.kirupa.com/t/array-control-problem/326914>\
**Category:** Uncategorized\
**Created:** [January 21, 2012, 10:18am UTC](https://forum.kirupa.com/t/array-control-problem/326914 "2012-01-21T10:18:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yavona](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yavona](https://forum.kirupa.com/u/yavona)\
**Post date:** [January 21, 2012, 10:18am UTC](https://forum.kirupa.com/t/array-control-problem/326914/1 "2012-01-21T10:18:17Z")

</div>

[COLOR=#000000][FONT=verdana]Hello, i’ve a problem about checking array with if statement… my code is above and i can’t see “it works” text on trace. I want to take the first value of an array after shuffle function, and i want to check it with if statement.[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]\_global.test\_array = new Array(“1”, “2”);[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]Array.prototype.shuffle = function():Array {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]var randarray = new Array();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]while (this.length\>0) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]randarray.push(this.splice(Math.round((this.length-1)\*Math.random()), 1));[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]return randarray;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]\_global.test\_array = \_global.test\_array.shuffle();[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]trace(\_global.test\_array[0]);[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]if (\_global.test\_array[0] == “1” or \_global.test\_array[0] == “2”) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]trace(“it works”);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]many thanks[/FONT][/COLOR]
