i-want-to-access-only-one-key-_id-from-object-of-array

questionsCategory: Questionsi-want-to-access-only-one-key-_id-from-object-of-array
1 Answers
admin Staff answered 7 months ago

Hi,
Using map you can access only one key from array of object. for example:

let data=[{“id”:”1″, “city”: “mumbai”},{“id”:”2″, “city”: “chennai”},{“id”:”3″, “city”: “delhi”}];
expected result:
data = [“mumbai”, “chennai”, “delhi”]
Solutions:
data = data.map(d=> d.city);