I have a array which i need to loop with map function and return object like a
{ 'acc' : anyValue }
I have a array which i need to loop with map function and return object like a
{ 'acc' : anyValue }
You can try the following way:
var arr = [
{id: 1, name: "values 1" } ,
{id: 1, name: "values 2" }
];
arr = arr.map(({name}) => ({'acc' : name}));
console.log(arr);
You're currently not returning anything in your map callback function, therefore you get:
[undefined undefined]
Try these instead:
arr.map((key, val) => ({ acc: val }) )
arr.map((key, val) => { return {acc: val} } )