Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JavaScript loop through array of Object

I have this array of object:

let obj =  [ 
    { "id_feed": 114, "date_upd": 1666808102 },
    { "id_feed": 115, "date_upd": 1666808102 },
    { "id_feed": 116, "date_upd": 1666808102 },
] ;

I want to get all the keys and value. Note: this keys can dynamic, it could be anything.

So to get this I am trying :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Object.keys( obj ).forEach( ( item ) => {
    console.log( obj[item] )
})

But seems like doing wrong 🙁

Expected Output:

id_feed  = 114
date_upd = 1666808102
id_feed  = 115
date_upd = 1666808102
id_feed  = 116
date_upd = 1666808102

>Solution :

Using Object.keys() can also do it

let obj =  [ 
    { "id_feed1": 114, "date_upd": 1666808102 },
    { "id_feed2": 115, "date_upd": 1666808103 },
    { "id_feed3": 116, "date_upd": 1666808104 }
] 

obj.forEach(d1 => {
  Object.keys(d1).forEach(d2 => {
    console.log(d2 + ' = ' + d1[d2])
  })
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading