You can create a new list by mapping a function over each item of a list.
Example: y is created by mapping n => n + 1 over each item of x:
const x = [10, 20, 30];
const y = x.map(n => n + 1);
x;
//=> [10, 20, 30]
y;
//=> [11, 21, 31]
You can also turn a list of things into a list of other things: x is a list of numbers and y is a list of strings.
const x = [1, 2, 3];
const y = x.map(n => '🌯'.repeat(n));
y;
//=> ["🌯", "🌯🌯", "🌯🌯🌯"]
In your case you need to turn a list of n objects into a list of n × 2 strings. (Each object "producing" two strings; a first name and a last name)
For this we need to use Array#flatMap which map a function over each item of a list and flatten the result of the function into the new list.
A simple example will make this all clear:
const x = ['🌯', '🥑'];
const y = x.flatMap(n => [n, n]);
y;
//=> ["🌯", "🌯", "🥑", "🥑"]
Now let's solve your issue!
const y = x.flatMap(({firstName, lastName}) => [firstName, lastName]);
console.log(y);
<script>
const x =
[ { firstName: "Daniel"
, lastName: "James"
}
,
{ firstName: "Laura"
, lastName: "Murray"
}
];
</script>
Is there a simple way to do it?Nope, because there is no concept likestring array