I am trying to iterate this object. I have checked code over the internet and found that Object.enteries can work but so far it is only returning 1st CustomerName i.e. "Asad". I want to iterate it to the complete array not just the first one.
var myObject = {
"records": [
{
"id": "recDBqsW7C3Dk3HMd",
"fields": {
"Latitude": "24.898907",
"Longitude": "67.117303",
"CustomerName": "Asad"
},
"createdTime": "2020-10-07T04:43:31.000Z"
},
{
"id": "recGlfTbUcEvP46Lf",
"fields": {
"Latitude": "24.907641",
"Longitude": "67.1088035",
"CustomerName": "Umar"
},
"createdTime": "2020-10-07T04:44:11.000Z"
},
{
"id": "recfsQsoznDyWPDe8",
"fields": {
"Latitude": "24.911112",
"Longitude": "67.105117",
"CustomerName": "Ali"
},
"createdTime": "2020-10-06T09:11:05.000Z"
}
]
};
Object.entries(myObject).forEach(([key, value], index) => {
console.log( value[index].fields.CustomerName); // key ,value
});
Result:
"Asad"
myObject, and its property name is "records".indexis an index intomyObjectproperties, why are you using it as an index forvalue?