I have an example of javascript array of object within an object there is object. So I basically want only that into one dimensional array.
I have searched lots of Q's on SO but none of them as per my requirement.
What I have
[
{
"id": "59cf758f7bdf8d2e0c1c68c7",
"value": {
"city": "Mahbubnagar",
"state": "Andhra Pradesh",
"country": "India"
}
},
{
"id": "59cf758f7bdf8d2e0c1c68c8",
"value": {
"city": "Udgir",
"state": "Maharashtra",
"country": "India"
}
},
{
"id": "59cf758f7bdf8d2e0c1c68c9",
"value": {
"city": "Umarga",
"state": "Maharashtra",
"country": "India"
}
},
{
"id": "59cf758f7bdf8d2e0c1c68ca",
"value": {
"city": "Umarkhed",
"state": "Maharashtra",
"country": "India"
}
},
{
"id": "59cf758f7bdf8d2e0c1c68cb",
"value": {
"city": "Umred",
"state": "Maharashtra",
"country": "India"
}
}
]
And I simply want this array of objects into an array
[
"59cf758f7bdf8d2e0c1c68c7",
"Mahbubnagar",
"Andhra Pradesh",
"India",
],[
"59cf758f7bdf8d2e0c1c68c9",
"Umarga",
"Maharashtra",
"India",
],[
"59cf758f7bdf8d2e0c1c68ca",
"Umarkhed",
"Maharashtra",
"India",
],[
"59cf758f7bdf8d2e0c1c68c7",
"Mahbubnagar",
"Andhra Pradesh",
"India",
],
The array of objects could be have more children in other words you can say its dynamic content.
What I have used so far is
var object= property.value.elements;
var finalArray = object.map(function (obj) {
return obj.id;
});
console.log(finalArray);
Which is giving me only list of Id's
It's not duplicate question please verify before marking it as Duplicate.
[{}, {}...]