i have a nested object like this
const sections = {
text : {id : 1 , text: 'something' },
link : {id : 2 , text: 'something' , 'href' : 'http://example.com' },
social : {
telegram : {id : 3 , text : 'my telegram' , 'address' : '@mytelegram'} ,
twitter : {id : 4 , text : 'my twitter' , 'address' : '@mytwitter'} ,
}
}
i want to have a function giving me each section by passing property key to it
function getSection(key ){
console.log(sections[key]);
}
this works for text and link but if i want social.telegram this wont work
is there any way to solve this without some sort of looping throw sections ?
------------- edit ------------------------
also what if i want to set the value for the sections object
something like
function setSectionText(key , newText)
{
sections[key].text = newText ;
}