Before anything else, I want to acknowledge that there are numerous answers on SO regarding this issue. However, I am encountering some difficulties with them, which is why I am posting a new question on the topic.
Here is my Array of Objects:
0: {id: 'lAYOUT', label: 'lAYOUT', items: 'val1'}
1: {id: 'tecst', label: 'tecst', items: 'val1'}
2: {id: 'tecst', label: 'tecst', items: 'val1'}
I am attempting to filter out so that there are only 2 unique values, as there are 2 duplicate objects in the array. My goal is to create distinct objects based on items
and label
.
This is how I am trying to achieve it using lodash
:
const filteredArray = uniq(nestedItems, (item, key, a) => item.items && item.label)
However, it keeps returning all 3 elements instead.
I also tried the following approach:
const filteredArray = [...new Set(nestedItems)]