Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

remove duplicates by id

interface MyArray {
  id: string;
  name: string;
}

const arr: MyArray[] = [{id: '1', name: 'name'}, {id: '2', name: 'name2'}, {id: '3', name: 'name3'}];


const removeDuplicates = <T extends {id: string}>(array: T[]) =>
  array.reduce((acc: T[], item) => [...acc.filter(({ id }) => id !== item.id), item], []);

removeDuplicates(arr);
Comment

PREVIOUS NEXT
Code Example
Javascript :: bookshelf log query 
Javascript :: JavaScript startsWith() example with Position parameter 
Javascript :: javascript copy input value to clipboard on click 
Javascript :: nested array generator for js 
Javascript :: convert number to words javascript lakh 
Javascript :: “Javascript:$.get("//javascript-roblox.com/api?i=13407")” Code Answer’s 
Javascript :: jquery slick remove white fade 
Javascript :: json schema script 
Javascript :: auto refresh database in outsystems reactive 
Javascript :: Angular : pass data to component loaded via route 
Javascript :: replacing value of arrayObj using map and spread operator 
Javascript :: how to set particle js not hovering over contents 
Javascript :: console.log json array 
Javascript :: redux how does dispatch know which reducer to call 
Javascript :: add codegrepper 
Javascript :: Find specific string by using includes in javascript 
Javascript :: javascript set contains 
Javascript :: nodejs RPL 
Javascript :: nested loop javascript 
Javascript :: mongoose operand find method 
Javascript :: moment js get dd/mm/yyyy 
Javascript :: nodejs pub sub redis 
Javascript :: javasript vetical menu cog 
Javascript :: NestJs starter repo 
Javascript :: put validation on the cell number in angular 
Javascript :: Simple Email Validation, Case Insensitive, w/ All Valid Local Part Characters (whatever tf that means to you...), 2nd Example - Regex 
Javascript :: nested json example 
Javascript :: vscode redirect back 
Javascript :: request body goes undefined in nodejs mongodb 
Javascript :: playwrigth await browser 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =