Below is my object inside array. I need to display the list reading this array.
let res = {
details: [
{
"code":"123",
"name":"tye"
},
{
"code":"456",
"name":"San Joaquin"
},
{
"code":"789",
"name":"Stanislaus"
},
]
};
I need to read and display details.code which does not work. I need to display list of all code
123
456
789
I do not need individual to display. Not like details[0].code. Below is what i have done
let det = [];
Object.keys(res.details).forEach((code) => {
det.push(res.details[code])
});
Here det does not give list of code. How to achieve this?
res.details.forEach(({ code }) => console.log(code))res.details.forEach(function(element) { console.log(element); });det.push(res.details[code.code])