Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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'));
Source by reactgo.com #
 
PREVIOUS NEXT
Tagged: #remove #duplicate #objects #based #id #array #angular
ADD COMMENT
Topic
Name
8+4 =