问题:
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; } } console.log(include([1, 2, 3, 4], 3)); // true console.log(include([1, 2, 3, 4], 6)); // undefined
解决方案:
参考一: https://en.stackoom.com/question/bQ7参考二: https://stackoom.com/question/bQ7