Answers for "how to remove duplicate values from array of objects in javascript"

-1

remove duplicates from array of objects javascript

let arr = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"}];

const uniqueArray = arr.filter((v,i,a)=>a.findIndex(t=>(t.name===v.name))===i)
console.log(uniqueArray);
Posted by: Guest on June-21-2021
0

remove duplicates objects from array javascript

arr.reduce((acc, current) => {
  const x = acc.find(item => item.id === current.id);
  if (!x) {
    return acc.concat([current]);
  } else {
    return acc;
  }
}, []);
Posted by: Guest on November-09-2020
-1

remove duplicates objects from 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])
Posted by: Guest on February-23-2021

Code answers related to "how to remove duplicate values from array of objects in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language