Last active
April 23, 2018 13:55
-
-
Save JakeDuke/595c5d97fc194e14d1030264875a0291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function removeSpeaker(speakerName){
let new_speakers = nestedObject.speakers.filter(function(el) {
return el.name !== speakerName;
});
nestedObject.speakers = new_speakers
}