I have below array of objects:
var all = [
{f1: "v1", f2: "v2"},
{f1: "v1", f2: "v2", f3: "v3"},
{f1: "v1", f2: "v2", f3: "v3", f4: "v4"},
{f1: "v1", f2: "v2", f3: "v3", f4: "v4", fn: "vn"}
];
Desired Output:
[f1, f2, f3, f4, f5, ...., fn];
Currently Using:
all.reduce((sum, item) => ([...new Set([...sum, ...Object.keys(item)])]), []);
Working Example: codepen
Any suggestions using es6 or any new js feature, for better performance.
new Set(all.map(o => Object.keys(o)).flat())