I am a rookie at javascript, I have just gone through few of array methods and wanted to play with it, I’m stuck at this code that I’ve written:
function customFindProperty(arrayToFind,requiredItem){
var elementIndex = 0;
function isRequiredItem(item){
elementIndex++;
return item==requiredItem;
}
elementFound = arrayToFind.some(isRequiredItem);
if(elementFound){
return arrayToFind(elementIndex);
} else{
alert("Element Not Found");
return undefined;
}
}
var myElement = customFindProperty([1,2,3,4,5],3);
This gives me the error TypeError: Object is not a function I think I’m not even missing any semicolons.
Additional Info:
typeof customFindProperty returns “function”
Note
Don’t know how to close this question I found the answer it’s a simple typing mistake I was trying to return arrayToFind(elementIndex) instead of arrayToFind[elementIndex]
You are using parentheses instead of square brackets for your array access.
arrayToFind(elementIndex);should bearrayToFind[elementIndex];.