问题:
This question already has an answer here: 这个问题已经在这里有了答案:
What is the best way to find if an object is in an array? 查找对象是否在数组中的最佳方法是什么?
This is the best way I know: 这是我知道的最好方法:
function include(arr, obj) {
for(var i=0; i<arr.length; i++) {
if (arr[i] == obj) return true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
解决方案:
参考一: https://stackoom.com/question/bQ7/查找项目是否在JavaScript数组中的最佳方法-重复参考二: https://oldbug.net/q/bQ7/Best-way-to-find-if-an-item-is-in-a-JavaScript-array-duplicate
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4330211