I have an object that has an array inside with another object inside. I iterate over the object and array to print out the first name and last name of the people inside the array of objects. I am wondering if there is a better way to do this. Without having to use obj[i].first_name + " " + obj[i].last_name
Here is my code
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 : 'Choi'},
{first_name : 'Martin', last_name : 'Puryear'}
]
}
for(item in users)
{
console.log(item);
var obj = users[item]
for(var i = 0; i < obj.length; i++)
{
var obj2 = obj[i];
var name = "";
for(j in obj2)
{
name += obj2[j] + " ";
}
console.log(name);
name ="";
}
}
obj[i].first_name + " " + obj[i].last_name
? \$\endgroup\$ – 200_success Jan 30 '17 at 5:10