Say I have an object like this:
var families =
[
{ dad: 'bob', mom: 'sue', income: 10 },
{ dad: 'john', mom: 'jane', income: 5 }
];
Is there a fancy way to transform this into the following:
[ 'bob', 'sue', 'john', 'jane' ];
I know I could do it like this:
var people = [];
for (var index = 0; index < families.length; index++)
{
people.push(families[index].dad);
people.push(families[index].mom);
}
However I like to use Javascript's build-in array functions whenever possible (filter, map, forEach, etc). The best I could figure is using 'map':
var people = families.map(function(family)
{
return [family.dad, family.mom];
});
But that doesn't do what I want:
[ [ 'bob', 'sue' ], [ 'john', 'jane' ] ]
Is there any built-in that can do what I want? Thanks!
.flat()at the end?