js怎么判断某个对象是否在数组中
答案:2 悬赏:20 手机版
解决时间 2021-02-20 19:28
- 提问者网友:聂風
- 2021-02-20 05:56
js怎么判断某个对象是否在数组中
最佳答案
- 五星知识达人网友:几近狂妄
- 2021-02-20 07:05
用indexOf,假设你要判断a在不在数组arr中:
if(arr.indexOf(a) != -1){
console.log(a+'在数组中');
}
if(arr.indexOf(a) != -1){
console.log(a+'在数组中');
}
全部回答
- 1楼网友:北方的南先生
- 2021-02-20 07:53
可以使用indexof函数
definition and usage
the indexof() method searches the array for the specified item, and returns its position.
the search will start at the specified position, or at the beginning if no start position is specified, and end the search at the end of the array.
returns -1 if the item is not found.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯