I am receiving this error in my console. Error is happening within my for loop Not sure why but when I console.log(manchesterUnited.[0].salary); I get not errors. I am new to JS so it could be something minor. Uncaught TypeError: Cannot read property 'salary' of undefined.
var footballer = function(name, position, age, salary, number) {
this.name = name;
this.position = position;
this.age = age;
this.salary = salary;
this.number = number;
}
var manchesterUnited = [];
manchesterUnited[0] = new footballer("Zlatan", "striker", 37, 20, 9);
manchesterUnited[1] = new footballer("Rooney", "forward", 33, 15, 10);
var totalSalary = 0;
for(var i = 0; i <= manchesterUnited.length; i++){
totalSalary = manchesterUnited[i].salary + totalSalary;
}
console.log(totalSalary);
Thank you.