@nonconformiste

Как убрать объекты дубликаты из массива?

new [...Set] не помогает
Array

[
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Slate"
    },
    {
        "name": "Size",
        "value": "2T"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "XX-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "X-Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "XX-Large"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "XX-Large"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Slate"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "XX-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "3T"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Slate"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "2T"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "2T"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "3X-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "3X-Large"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "3X-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "4T"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "X-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "3T"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "X-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "X-Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "X-Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Slate"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "XX-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Medium"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "X-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "4T"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "2T"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Asphalt"
    },
    {
        "name": "Size",
        "value": "XX-Large"
    },
    {
        "name": "Fit Type",
        "value": "Youth"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "3T"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    },
    {
        "name": "Color",
        "value": "White"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Lemon"
    },
    {
        "name": "Size",
        "value": "Small"
    },
    {
        "name": "Fit Type",
        "value": "Women"
    },
    {
        "name": "Color",
        "value": "Olive"
    },
    {
        "name": "Size",
        "value": "Large"
    },
    {
        "name": "Fit Type",
        "value": "Men"
    }
]

  • Вопрос задан
  • 63 просмотра
Решения вопроса 1
0xD34F
@0xD34F Куратор тега JavaScript
Object
  .values(arr.reduce((acc, n) => ((acc[n.name] ??= {})[n.value] = n, acc), {}))
  .flatMap(Object.values)

или

arr.filter((n, i, a) => n === a.find(m => m.name === n.name && m.value === n.value))
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы