Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

remove duplicates objects from array angular

this.item = this.item.filter((el, i, a) => i === a.indexOf(el))
Comment

remove duplicates from array of objects

const arr = [
  { id: 1, name: "test1" },
  { id: 2, name: "test2" },
  { id: 2, name: "test3" },
  { id: 3, name: "test4" },
  { id: 4, name: "test5" },
  { id: 5, name: "test6" },
  { id: 5, name: "test7" },
  { id: 6, name: "test8" }
];

const filteredArr = arr.reduce((acc, current) => {
  const x = acc.find(item => item.id === current.id);
  if (!x) {
    return acc.concat([current]);
  } else {
    return acc;
  }
}, []);
Comment

remove duplicate objects based on id from 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'));
Comment

how to check duplicate objects in array and remove in angular

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)
Comment

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);
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript import particular class from file 
Typescript :: an apparmor policy prevents this sender from sending this message to this recipient 
Typescript :: convert image path to base64 typescript 
Typescript :: add comma for input number automatically typescript 
Typescript :: count number of set bits in number java 
Typescript :: what is typescript 
Typescript :: how to count the number of the digits in an input in python 
Typescript :: Error: Missing "key" prop for element in iterator 
Typescript :: styled-components error in typescript 
Typescript :: check if schema exists sql server 
Typescript :: router configuration vue 
Typescript :: find all running ports node 
Typescript :: git status without untracked files 
Typescript :: how to edit multiple inputs react 
Typescript :: google sheets sumif 
Typescript :: absolute refrence of cell in excel 
Typescript :: simple input for games javascript 
Typescript :: append contents of one file to another 
Typescript :: give all element in a list starts with string 
Typescript :: how to create empty object typescript 
Typescript :: main.ts is missing from the typescript compilation 
Typescript :: arrow function in ts 
Typescript :: typescript type from array 
Typescript :: spyon observable 
Typescript :: add bullet points in text widget flutter 
Typescript :: react-native use typescript 
Typescript :: preventing letters from being placed in an input ts 
Typescript :: alphabets range using re 
Typescript :: O arquivo yarn.ps1 não pode ser carregado porque a execução de scripts foi desabilitada neste sistema 
Typescript :: typescript function 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =