Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

use set to remove duplicates in javascript

const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
Comment

remove duplicates in javascript array (using set)

const arrayWithDuplicateValues = [1, 2, 2, 3, 4, 5, 6, 7, 7, 7, 8, 9];
const uniqueValues = [...new Set(arrayWithDuplicateValues)];

console.log(uniqueValues);

//same code with spread operator


const arrayWithDuplicateValues = [1, 2, 2, 3, 4, 5, 6, 7, 7, 7, 8, 9];
const uniqueValues = Array.from(new Set(arrayWithDuplicateValues));

console.log(uniqueValues);
Comment

PREVIOUS NEXT
Code Example
Javascript :: show console chrome mac 
Javascript :: add keyup event javascript 
Javascript :: map object es6 
Javascript :: how to redirect in ionic react 
Javascript :: on_raw_reaction_add example 
Javascript :: mongoose pull each 
Javascript :: quicksettins.js 
Javascript :: double matrix iteration in react 
Javascript :: js sort by array key value 
Javascript :: get api call in jquery 
Javascript :: update node ubuntu 
Javascript :: javascript get clipboard contents 
Javascript :: eslint no-param-reassign 
Javascript :: document load javascript 
Javascript :: how to get session javascript ws3schools 
Javascript :: jetbrains vscode 
Javascript :: js console log without spaces 
Javascript :: refresh page js 
Javascript :: scroll to bottom react 
Javascript :: get width of a dom element js 
Javascript :: check if somethin exist in an object js 
Javascript :: css 2 components side by side react 
Javascript :: using .indexOf() in jShell 
Javascript :: how to send an embed message discord.js 
Javascript :: react js input autocomplete off 
Javascript :: gettype js 
Javascript :: outsystems close feedback message 
Javascript :: redirect not found in react-router-dom 
Javascript :: jquery watch checkbox change 
Javascript :: usehistory example 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =