I'm running a 'for' loop to check if the elements in the winOptions array are in the oneNums array. However, every time I use indexOf property it sends back -1 even if the number is in the oneNums array. Is it possible it returns that because ['1','2'] is different that [1,2]? How can I fix this.
I have this variables:
var oneNums = []; var winOptions = [[1,2,3],[4,5,6],[7,8,9],[1,5,9],[3,5,9],[1,4,7],[2,5,8],[3,6,9]]; var a; And this jQuery function:
$('.btn-xo').click(function(){ if (turn === 'one'){ $(this).text(pickOne); $(this).prop('disabled', true); oneNums.push($(this).val()); oneNums.sort(function(a, b){ return a - b; }); for(var i = 0; i < winOptions.length; i++){ for(var j = 0; j < winOptions[i].length; j++){ a = oneNums.indexOf(winOptions[i][j]); if (a === -1){ p1 = []; break; } else { p1.push(oneNums[a]); console.log('aca'); } } } console.log(a); turn = 'two'; count += 1; }
oneNums.push(parseInt($(this).val(), 10));can check parsing it?