nn2 nn2 - 1 year ago 90
Javascript Question

JavaScript is in array

Let's say I have this:

var blockedTile = new Array("118", "67", "190", "43", "135", "520");

There's more array elements but those are just few for readability purposes. Anyways, I could do a "for" loop but it would do 500 loops everytime you click on the map... is there any other way to see if a certain string is in an array?

Answer Source

Try this:

if(blockedTile.indexOf("118") != -1)
   // element found