I am currently facing an issue with a basic array that contains numbers. My goal is to determine if a particular number is present in the array and, if so, return the index where it can be found. The number I am searching for is generated by a function. However, when I execute the code using findIndex(<number>);
, I encounter a
typeError: <number> is not a function
. Below is my code snippet:
const numberProducer = function(n) {
return n + 1;
};
var number = numberProducer(1);
var arr = [1, 2, 3, 4];
var isNumberInArray = arr.findIndex(number);
if (isNumberInArray === -1) {
<do something>
}
else {
<do something>
}
Even after assigning a fixed value to findIndex()
, the same error persists.