Javascript rimuovere dupes dalla matrice di oggetti

Esempi di codice

0
0

rimuovere duplicati oggetti da array javascript

function remove_duplicate_objects(data,prop) {
    var seen = {};
    data = data.filter(function (entry) {
      if (seen.hasOwnProperty(entry[prop])) {
        return false;
      }

      seen[entry.prop] = entry;
      return true;
    });
    return data
  }

const new_array = remove_duplicate_objects([array with objects inside])
-1
0

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' }]

Pagine correlate

Pagine di esempio simili

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
English
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................