問題:
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