Having trouble accessing objects. They are printing as undefined. Help! I need the code to print the student names.
let students = [
{name: 'Remy', cohort: 'Jan'},
{name: 'Genevieve', cohort: 'March'},
{name: 'Chuck', cohort: 'Jan'},
{name: 'Osmund', cohort: 'June'},
{name: 'Nikki', cohort: 'June'},
{name: 'Boris', cohort: 'June'}
];
function objPrint() {
for (var i=0; i<students.length; i++) {
console.log("Name: " + students[i][0] + " Cohort: " + students[i][1])
}
}
students[i]is not an array,students[i]is an object containingnameandcohortproperties. So instead of doingstudents[i][0], you want to dostudents[i].name.