Why is my IndexOf function returning -1 when I know the value is in the array?
This issue has been confirmed with console.log using the following code (paraphrased for simplicity):
var xtiles = [];
function assignValue(tile) {
xtiles.push(tile); //tile is 1 at this point
checkArray();
}
function checkArray() {
var temp = xtiles.indexOf(1);
console.log(temp); //this returns a -1
console.log(xtiles[0]); //this returns a 1
}
Based on the data, 'temp' should be equal to 0 since there is a 1 in index 0 of the array xtiles. What could be causing this mismatch?