本文介绍了JavaScript在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个:
var blockedTile = new Array("118", "67", "190", "43", "135", "520");
还有更多的数组元素,但为了便于阅读,这些元素很少。无论如何,我可以做一个for循环但每次点击地图时它会做500个循环......有没有其他方法可以查看某个字符串是否在数组中?
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?
推荐答案
试试这个:
if(blockedTile.indexOf("118") != -1)
{
// element found
}
这篇关于JavaScript在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!