I currently have this Object:
schoolsObject = [{
"college_1":
{
"id":"college_1",
"location":"Victoria",
"name":"College One"
},
"college_2":
{
"id":"college_2",
"location":"Tasmania",
"name":"College Two"
}
}];
I want to remove the top level keys ie. college_1, college_2 and 'flatten' the object out like this, so I have no 'top level' keys:
flatSchoolsObject =
[{
"id":"college_1",
"location":"Victoria",
"name":"College One"
},
{
"id":"college_2",
"location":"Tasmania",
"name":"College Two"
}];
Here is my latest attempt, I've made a lot of different try's but have not been documenting them:
// schoolIDs = Object.keys(schoolsObject);
var schools = {};
for(var i=0; i<Object.keys(schoolsObject).length; i++){
for (var property in schoolsObject) {
if (schoolsObject.hasOwnProperty(property)) {
schools[i] = {
'id': schoolsObject[property]['id'],
'name' : schoolsObject[property]['name'],
'location': schoolsObject[property]['location'],
};
}
}
}
console.log(schools)
Obviously this one is not what I'm after as it leaves me with Object {0: Object, 1: Object}.
Is what I want to do here possible or am I looking at it the wrong way?