indexOf(“1”) returns -1 , when there is a 1 in my array.
I want to know where every position of “1” is, cause I want to eventually want to create a loop to count every how many time “1” is in the array.
var first_sudoku = [ ["X", "X", "X", "X"], ["1", "X", "2", "X"], ["X", "1", "4", "X"], ["2", "X", "X", "1"], ]; function counter_for_numbers_in_chart(sudoku) { console.log(sudoku.indexOf("1")); } counter_for_numbers_in_chart(first_sudoku);
Advertisement
Answer
how about this:
first_sudoku.indexOf(first_sudoku[1])
and you get 1.
if you use:
first_sudoku.indexOf(first_sudoku[4])
you get -1