actionscript 3 - AS3: How to check if a value already exists in the Array before adding with FOR loop? -
i believe simple not simple enough :). ideas how check if value exists in array before adding value using loop?
i have far , doesn't work want because array can contain duplicate values!
var n:int = 5; var cnt:int; (var = 0; < n; i++) { cnt = randomthief(); (var = 0; < loto5.length; a++) { if (loto5[i] == cnt) { loto5[i] = cnt; } } }
you can use indexof() method of array class check if value exists :
var index:int = loto5.indexof(cnt); indexof() returns -1, if value doesn't exist. here example of how check :
if (loto5.indexof(cnt) >= 0) { // }
Comments
Post a Comment