Given the following:
let arr = [
{ name: 'AAA' },
{ name: 'BBB' },
{ name: 'CCC' },
{ name: 'DDD' },
{ name: 'EEE' },
{ name: 'FFF' }
];
I'm trying to covert the above to a new array with just the values. I tried:
console.log(Object.values(arr));
but this didn't work.
The end result that I am after is just the values within the one new array, that is:
new_arr = ['AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF'];
arr.map(value => value.name)
Use array map or each or any other loop iteration. The simple one is given below.
let arr = [
{ name: 'AAA' },
{ name: 'BBB' },
{ name: 'CCC' },
{ name: 'DDD' },
{ name: 'EEE' },
{ name: 'FFF' }
];
console.log(arr);
const newarr = arr.map(function(e, i) {
return e.name
});
console.log(newarr);
Yes, you can try this syntax
let arr = [
{ name: 'AAA' },
{ name: 'BBB' },
{ name: 'CCC' },
{ name: 'DDD' },
{ name: 'EEE' },
{ name: 'FFF' }
];
let array = arr.map((e)=>Object.values(e)[0])
console.log(array);