I'm trying to loop an array that contains objects and I keep getting and error: "Cannot set property 'color' of undefined". What am I doing wrong?
var ObjectTest = function(something1, something2){
this.Name = something1;
this.Job = something2;
this.color = '';
this.numbers = [];
}
var first = new ObjectTest('Paul', 'teacher');
var second = new ObjectTest('Jane', 'doctor');
var third = new ObjectTest('Mike', 'student');
var someArray = [];
someArray.push(first, second, third);
console.log(someArray);
for(var i =0; i <= someArray.length; i++){
someArray[i].color = 'red';
};
<=in the loop should be<.i < someArray.length. If the array has 3 elements, the length is 3 and the indexes are 0, 1, and 2.