javascript - accessing an objects key in js -


i have array of objects

 const relationdata = [       {         kids: [           { text: 'newborn', value: 'newborn' },           { text: 'for under 5\'s', value: 'under5' },           { text: 'teenagers', value: 'teenagers' }         ]       }, 

how access word kids in here? want check if myvalue == kids?

i have tried doing:

for (var key in data) {   console.log(key); } 

but seems return me index

ps dont want mention word kids wont resuable

you can loop through keys of each obj in relationdata below

for (var index in relationdata) {   var keys = object.keys(relationdata[index]);   console.log(keys.indexof("kids") > -1)// relationdata has object key of "kids" } 

"kids" can variable can reuse other key names


Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

meteor - inserting data to database gives error "insert failed: Method '/texts/insert' not found" -