If I have the following array of objects:
const arr = [{ id: 'A', version: 0, name: 'first' },
{ id: 'A', version: 1, name: 'first' },
{ id: 'B', version: 0, name: 'second' },
{ id: 'A', version: 2, name: 'first' },
{ id: 'B', version: 1, name: 'second' }];
I want to use this array as input for creating two drop-down menus.
The first drop-down menu should display only the values A
and B
.
To achieve this, I can do the following:
const firstDropdownOptions = [...new Set(arr.map((el) => el.id))];
However, this code will only return ['A', 'B']
without any additional information about the properties of each object.
It would be more useful if the output looked like this:
[{ id: 'A', version: '0', name: 'first' }, { id: 'B', version: '0', name: 'second' }]
Do you have any suggestions on how to modify the code to return the desired array format?