Within javascript, I am trying to print the values from a few objects listed in an array in an object. The question has to do with drilling into objects/arrays with a for in loop. More specifically I'd like to avoid using a for loop if possible (I just learned for/in and am trying to understand it well)
The object looks like this:
var users = {
'Students': [
{ first_name: 'Michael', last_name : 'Jordan' },
{ first_name : 'John', last_name : 'Rosales' },
{ first_name : 'Mark', last_name : 'Guillen' },
{ first_name : 'KB', last_name : 'Tonel' }
],
'Instructors': [
{ first_name : 'Michael', last_name : 'Jackson' },
{ first_name : 'Martin', last_name : 'Puryear' }
]
};
How could i write a function that returns all of the names burried in this object? Id like to console log:
Students
1 - MICHAEL JORDAN
2 - JOHN ROSALES
3 - MARK GUILLEN
4 - KB TONEL
Instructors
1 - MICHAEL JACKSON
2 - MARTIN PURYEAR
Ive tried writing a couple for/in loops but I keep getting unexpected results. Thanks in advance for taking a look at this.