JavaScript 在数组中 [英] JavaScript is in array

查看:42
本文介绍了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 在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆