Skip to content

Instantly share code, notes, and snippets.

@JakeDuke
Last active April 23, 2018 13:55
Show Gist options
  • Save JakeDuke/595c5d97fc194e14d1030264875a0291 to your computer and use it in GitHub Desktop.
Save JakeDuke/595c5d97fc194e14d1030264875a0291 to your computer and use it in GitHub Desktop.
var nestedObject = {
speakers: [{name:"Elie"},{name:"Tim"},{name:"Matt"}],
data: {
continents: {
europe: {
countries: {
switzerland: {
capital: "Bern",
population: 8000000
}
}
}
},
languages: {
spanish: {
hello: "Hola"
},
french: {
hello: "Bonjour"
}
}
}
};
function addLanguage(language, halloLanguage){
nestedObject.data.languages[language] = {
hello: halloLanguage
};
}
function removeLanguage(language){
delete nestedObject.data.languages[language];
}
addLanguage('Russian', 'Darova');
function addCountry(country, capital, population){
nestedObject.data.continents.europe.countries[country] = {
capital: capital,
population: population
};
}
addCountry('Russia', 'Moscow', 145000000);
function removeCountry(country){
delete nestedObject.data.continents.europe.countries[country];
}
removeCountry('switzerland');
function addSpeaker(speakerName){
nestedObject.speakers.push({name: speakerName});
}
addSpeaker('Krasavchik');
function removeSpeaker(speakerName){
let new_speakers = nestedObject.speakers.filter(el => el.name !== speakerName);
nestedObject.speakers = new_speakers;
}
removeSpeaker('Matt');
console.log(nestedObject.speakers);
console.log(nestedObject.data.languages);
console.log(nestedObject.data.continents.europe.countries);
@colevandersWands
Copy link

function removeSpeaker(speakerName){
let new_speakers = nestedObject.speakers.filter(function(el) {
return el.name !== speakerName;
});
nestedObject.speakers = new_speakers
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment