The function expects 2 arguments - arr
and value
. You pass the value (56) in place of the arr
.
In addition, returning in the else
means that if the 1st item is not the requested value, the iteration would stop, and return "Not Found".
Pass the array to the function, and return "Not Found" after the loop ends:
function arrayCheck(arr, value) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === value) {
return i;
}
}
return "Not found";
}
var arr = [35, 56, 78, 90, 54];
console.log(arrayCheck(arr, 56));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…