I'm learning to use modern array methods on arrays, but is there a way I can use these methods on objects of arrays? If not is it better to store the entire object into an array?
var course = {
name: "My Javascript Tutorial",
awesome: true,
teachers: ["Brandon", "Shane", "Mike"],
students: [
{
name: "Cliff",
computer: {
OS: "macOS",
type: "iMac"
}
},
{
name: "Arthur",
computer: {
OS: "macOS",
type: "Macbook Pro"
}
},
{
name: "Donald",
computer: {
OS: "macOS",
type: "Windows PC"
}
}
]
};
course.forEach(function(item){
console.log(course.students[item].name + 'uses a ' + course.students[item].computer.type);
})
This is the Error I'm getting.
TypeError: Cannot read property 'students' of undefined