Let's pretend that:
var all=[
{firstname:'Ahmed', age:12},
{firstname:'Saleh', children:5 }
{fullname: 'Xod BOD', children: 1}
];
Expected Result ['firstname','age', 'children', 'fullname']: The union of the keys of all objects in this array:
all.map((e) => Object.keys(e) ).reduce((a,b)=>[...a,...b],[]);
It works well. However, I am looking for a higher performance solution using the method reducedirectly without map, I did the following, and it failed.
all.reduce((a,b) =>Object.assign([...Object.keys(a),...Object.keys(b)]),[])
source
share