I am new to javascript and was trying this code below.
This code was working properly but seems now its only returning -1.
Array.prototype.nthIndexOf = function (element,location) {
var index = -1;
for(var i=0; i< this.length; i++) {
if(element === this[i] && !--location) {
index = i;
break;
}
}
return index;
}
var findNumber = prompt("Please enter number to be found");
var positionAt = prompt("Please enter position");
var position = [1, 2, 3, 3, 2, 89, 34, 12].nthIndexOf(findNumber, positionAt);
console.log(position); // position is -1 all the time