Answers for "remove duplicates in object array javascript"

1

remove duplicates in array object javascript

//check one attribute
let person = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"}];

person = person.filter((item, index, self) =>
  index === self.findIndex((t) => (
    t.name === item.name
  ))
)

//check two attributes
let person = [{place: "uno", name: "john"}, {place: "duno", name: "jane"}, {place: "duno" ,name: "imelda"}, {place: "uno" ,name: "john"}];

person = person.filter((item, index, self) =>
  index === self.findIndex((t) => (
    t.place === item.place && t.name === item.name
  ))
)
Posted by: Guest on September-08-2021
-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
-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 "remove duplicates in object array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language