In typescript code I have an array with objects in it. When I call "getUsers(users)" function, it returns the result as I need, but in console I get this error "Uncaught TypeError: Cannot read property 'firstName' of undefined at getUsers (index.js:20) at index.js:23"
let users = [
{
firstName: "John",
lastName: "Doe",
age: 34
},
{
firstName: "Jack",
lastName: "Jackson",
age: 23
},
{
firstName: "Ann",
lastName: "Watson",
age: 24
}
];
function getUsers(users) {
for (var i = 0; i <= users.length; i++) {
console.log(users[i].firstName + " is " + users[i].age + " years old!");
}
}
getUsers(users);