Answers for "avoid duplicates array of objects in an array in angular"

1

remove duplicates objects from array angular

this.item = this.item.filter((el, i, a) => i === a.indexOf(el))
Posted by: Guest on June-14-2021
0

how to check duplicate objects in array and remove in angular

let arr = [
  {value: 'L7-LO', name: 'L7-LO'},
  {value: '%L7-LO', name: '%L7-LO'},
  {value: 'L7-LO', name: 'L7-LO'},
  {value: '%L7-LO', name: '%L7-LO'},
  {value: 'L7-L3', name: 'L7-L3'},
  {value: '%L7-L3', name: '%L7-L3'},
  {value: 'LO-L3', name: 'LO-L3'},
  {value: '%LO-L3', name: '%LO-L3'}
];
let obj = {};

const unique = () => {
  let result = [];
  
  arr.forEach((item, i) => {
    obj[item['value']] = i;
  });
  
  for (let key in obj) {
    let index = obj[key];
    result.push(arr[index])
  }
  
  return result;
}

arr = unique(); // for example; 

console.log(arr);
Posted by: Guest on June-18-2021

Code answers related to "avoid duplicates array of objects in an array in angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language