🧨
Array.from(new Set(myArr)) не фильтрует.
myArr.filter((el, index) => myArr.indexOf(el) === index) тоже не фильтрует
Size: a a a
🧨
S
🧨
myArr.reduce((acc, elem) => {
if (acc.find(exist => exist.id !== elem.id)) {
acc.push(elem)
}
return acc
}, [])
AB
"А": [
{
"id": 1,
"category_id": null,
"ru": "абзац",
"bash": "ҡыҙыл юл, яңы юл; абзац",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
{
"id": 2,
"category_id": null,
"ru": "абрикос",
"bash": "өрөк",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
{
"id": 3,
"category_id": null,
"ru": "автоматизировать",
"bash": "автоматлаштыр/ырға",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
{
"id": 4,
"category_id": null,
"ru": "автоматически",
"bash": "автоматик рәүештә",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
]
AB
🧨
myArr.reduce((acc, elem) => {
if (acc.find(exist => exist.id !== elem.id)) {
acc.push(elem)
}
return acc
}, [])
AB
myArr.reduce((acc, elem) => {
if (acc.find(exist => exist.id !== elem.id)) {
acc.push(elem)
}
return acc
}, [])
🧨
🧨
🧨
F
"А": [
{
"id": 1,
"category_id": null,
"ru": "абзац",
"bash": "ҡыҙыл юл, яңы юл; абзац",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
{
"id": 2,
"category_id": null,
"ru": "абрикос",
"bash": "өрөк",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
{
"id": 3,
"category_id": null,
"ru": "автоматизировать",
"bash": "автоматлаштыр/ырға",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
{
"id": 4,
"category_id": null,
"ru": "автоматически",
"bash": "автоматик рәүештә",
"created_at": 1576509912,
"updated_at": 1576509912,
"attach": [],
"type": "WORD"
},
]
🧨
F
AB
AB
F
F
VH
function getUniqueArray(array, primaryKey) {вот универсально на любой ключ
const entities = {};
const result = [];
array.forEach((value) => {
entities[value[primaryKey]] = value;
});
for (const key in entities) {
if (entities.hasOwnProperty(key)) {
result.push(entities[key]);
}
}
return result;
}
AB
F