This is my object:
"names": [{
"first": "Linda"
},
{
"first": "Maverick"
},
];
How can I convert this, so that I get an array with just the first
values:
["Linda", "Maverick"]
This is my object:
"names": [{
"first": "Linda"
},
{
"first": "Maverick"
},
];
How can I convert this, so that I get an array with just the first
values:
["Linda", "Maverick"]
Simply use Array#map
:
let data = {"names": [
{"first": "Linda"},
{"first": "Maverick"},
]};
let array = data.names.map(name => name.first);
console.log(array)
Use map with destructuring:
var names = [
{
"first": "Linda"
},
{
"first": "Maverick"
},
];
var res = names.map(({
first
}) => first);
console.log(res);