Having the following array:
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 need to use this as input for two drop-downs.
For the first drop-down it should show in the list only two values, A and B.
For doing that:
const firstDropdownOptions = [...new Set(arr.map((el) => el.id))];
Unfortunately, this returns ['A', 'B'] which doesn't contain any information about the other properties.
It would be more useful to be like:
[{ id: 'A', version: '0', name: 'first' }, { id: 'B', version: '0', name: 'second' }]
Any ideas on how to make it return the above array?
const firstDropdownOptions = arr.filter(({version}) => version === 0);.Areturn the object withversion: '0'and notversion: '1'? In fact,['A', 'B']may be any thing like:[{ id: 'A', version: '1', name: 'first' }, { id: 'B', version: '0', name: 'second' }]or[{ id: 'A', version: '2', name: 'first' }, { id: 'B', version: '0', name: 'second' }]or[{ id: 'A', version: '0', name: 'first' }, { id: 'B', version: '1', name: 'second' }]or ...object- there are 3 objects withAand 2 withB. So, what is the logic to choose which one of the objects for the letters?