Why array indexing returns -1?

var array = [1,2,3,4,5,6,7,8,9,10];

// From the DOM I get the number 7
var i = parseInt(document.querySelector(element));

array.indexOf(i);


The problem is that array.indexOf(i); returns -1... Why is this happening ?

Then there was a problem with (++). When indexing an array return 0 to select the next element I added to the end of the ++, but then again, why was returning 0, but if you try a second time, it all turned out.

Please write why this is happening ?

Thank you!
June 14th 19 at 20:53
2 answers
June 14th 19 at 20:55
Solution
print to the console the value of i
and will learn basic techniques debug your code before asking such elementary things
June 14th 19 at 20:57
Solution
The function returns -1 when doesn't find the requested result in the array, print to the console and i know what the problem is :)

UPD querySelector returns a DOM node,most likely it's bad
I checked. Case in querySelector. Good for you!) What should I use then ? - terry.Hagenes33 commented on June 14th 19 at 21:00
The fact that I don't know the problem and what you want from Dom'e and will blindly assume that you need i.innerText , it will return you the text from the nodes and then it parsite among - caroly commented on June 14th 19 at 21:03
Paul , I seem to have found what the problem is. The problem is ++. When you need to move on to the next value in the array, i++ works, but for some reason i does not increase... - terry.Hagenes33 commented on June 14th 19 at 21:06
I replied below - Jefferey.Carroll commented on June 14th 19 at 21:09

Find more questions by tags JavaScript