Search code examples
typescriptecmascript-6ecmascript-2016

how to convert objects properties into array with destruction es6


I have a belwo collection of objects assigned in

  products:{id: null, name: 6801},
     {id: null, name: 6802},
     {id: null, name: 6805}

I need to use map function and iterate the name need to convert into array of strings.

current code is written in 0 : {names: 6197} 1 : {names: 6801} 2 : {names: 6802}

but i need the below format

names:[6802,6802,6805],
    products.map(({name: names}) => ({names}));

Solution

  • You seem to be looking for

    products.map(({name}) => name);
    

    Don't put the result value in braces, that would form another object literal.