rimuovere oggetti duplicati in base a id da matrice angolare 8
function getUnique(arr, comp) {
// store the comparison values in array
const unique = arr.map(e => e[comp])
// store the indexes of the unique objects
.map((e, i, final) => final.indexOf(e) === i && i)
// eliminate the false indexes & return unique objects
.filter((e) => arr[e]).map(e => arr[e]);
return unique;
}
console.log(getUnique(arr,'id'));
rimuovere i duplicati oggetti array angolare
this.item = this.item.filter((el, i, a) => i === a.indexOf(el))
rimuovi oggetti duplicati in base all'id dall'array angular 8
function getUnique(arr, comp) {
// store the comparison values in array
const unique = arr.map(e => e[comp])
// store the indexes of the unique objects
.map((e, i, final) => final.indexOf(e) === i && i)
// eliminate the false indexes & return unique objects
.filter((e) => arr[e]).map(e => arr[e]);
return unique;
}
console.log(getUnique(arr,'id'));
come controllare gli oggetti duplicati nella matrice e rimuovere angolare
var filterArray = courseArray.reduce((accumalator, current) => {
if(!accumalator.some(item => item.id === current.id && item.name === current.name)) {
accumalator.push(current);
}
return accumalator;
},[]);
console.log(filterArray)
rimuovere duplicato in aaray di oggetti
const things = {
thing: [
{ place: 'here', name: 'stuff' },
{ place: 'there', name: 'morestuff1' },
{ place: 'there', name: 'morestuff2' },
],
};
const removeDuplicates = (array, key) => {
return array.reduce((arr, item) => {
const removed = arr.filter(i => i[key] !== item[key]);
return [...removed, item];
}, []);
};
console.log(removeDuplicates(things.thing, 'place'));
// > [{ place: 'here', name: 'stuff' }, { place: 'there', name: 'morestuff2' }]