题解 | #查找数组元素位置#
查找数组元素位置
http://www.nowcoder.com/practice/e7835a8113dd48afb15f77ef8d1dcb1d
function indexOf(arr, item) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === item) {
return i;
}
}
return -1;
}
let a = [1, 2, 3, 4];
let b = 3;
document.write(indexOf(a, b));