Why Am I Getting Typeerror: Array[i] Is Undefined?
So in my program, I have an array that contains a dictionary/hash of values and when I loop through the array, I get the value I need but any code after the for loop does not get e
Solution 1:
Issues
- You haven't enclosed your first
console.logfunction. - As an array is zero indexed making your condition
less than or equal towill make the loop try to use anundefinedpart of the array (bigger than total length). Therefore use theless thanoperator.
Fixed code
var array = [
{"name": "a", "pos": "C"},
{"name": "b", "pos": "B"},
{"name": "c", "pos": "W"},
];
for(var i = 0; i < array.length; i++) {
console.log(array[i]['pos']);
}
console.log("some other code");
Post a Comment for "Why Am I Getting Typeerror: Array[i] Is Undefined?"