The problem of automatic conversion of JS data subscript

var arr = [1,2,3,4,5,6,7]
for(var j in arr){
   console.log(j+1);
   console.log(j-1);
}

automatically converts j to string processing when outputting jroom1.
will be processed digitally when outputting jmur1.
what is the reason for this?

Mar.02,2021
The variables of the

for in loop are all strings (index), + can be used as string concatenators, you can change it to
console.log (+ jung1);


upstairs positive solution.
add that for in traversal is not recommended for arrays.
get into the habit of writing canonical code.

Menu