I want to create an object which will look like
{
'Andy':{
'Age' : 50,
'Sport' : 'Football'
},
'Brenda':{
'Age' : 33,
'Sport' : 'Soccer'
}
}
I'm trying to create this with JavaScript. I am able to get the strings via various api calls. My code looks like
const obj = {};
for (let i = 0; i < 2; i++) {
const name = getName(i);
const age = getAge(i);
const sport = getSport(i);
const newObj = {
name:
{
'ageInYears' : age,
'mainSport': sport
}
};
obj+= newObj; //doesn't work
obj.push(newObj); //fails, probably because push is for an array
obj.concat(newObj); // doesn't work
}
Can any one explain what I need to do