I have an array of objects like this:
const data = [
{ id: '1', label: 'Last Name', value: 'Smith' },
{ id: '1', label: 'Last Name', value: 'Blogs' },
{ id: '2', label: 'First Name', value: 'John' },
{ id: '2', label: 'First Name', value: 'Joe' }
];
I'm trying to get an output like this:
const output = [
{key: 'Employee', value: 'John Smith'},
{key: 'Employee', value: 'Joe Blogs'}
];
I was looking at using reduce, but am stuck on how to properly get a condition to say that if id is 2, then add to output.value, and if id is 1 then concat output.value to the value already there.
Both id 1 and id 2 are dynamic and can grow. Id 1 will always be last name and id 2 will always be first name.
John Blogs!?