I have this array:
let oldarr = [{typeid:1,percent:50,key:1, name:"ger"},
{typeid:3,percent:50,key:2, name:"geghr"},
{{typeid:5,percent:50,key:3, name:"ggdfer"}]
I want to create a new one that looks like this:
let newarr = [{id:'', percent:''}]
The newarr‘s id is equal to typeid of oldarr. How to create new array?
>Solution :
You could achieve this using the map function:
let oldarr = [{typeid:1,percent:50,key:1, name:"ger"},
{typeid:3,percent:50,key:2, name:"geghr"},
{typeid:5,percent:50,key:3, name:"ggdfer"}];
let newArray = oldarr.map(item=> ({id : item.typeid, percent: item.percent}));
console.log(newArray);