In the realm of JavaScript, a key is represented as a string due to its nature as an object within the Object.
To manipulate this behavior, you can convert the string into an int or utilize the prefix +
.
var arrayOfNumbers = [1, 2, 3, 4, 5, 6, 78];
for(var index in arrayOfNumbers) {
var v = parseInt(index) + 1;
console.log(v);
}
When applying the workaround method: use a prefix
var arrayOfNumbers = [1, 2, 3, 4, 5, 6, 78];
for(var index in arrayOfNumbers) {
var v = parseInt(index) + 1;
console.log(v);
}
var arrayOfNumbers = [1, 2, 3, 4, 5, 6, 78];
for(var index in arrayOfNumbers){
var v = +index + 1;
console.log(v);
}