Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript spread array without duplicates

// How to ES6 spread arrays without duplicates using Set
// Because each value in the Set has to be unique, the value equality will be checked.
let eventNamesArray = ['onMutation', 'onError']
eventNamesArray = [...new Set([...eventNamesArray, 'onReady', 'onError'])]
// ['onMutation', 'onReady', 'onError']

// if you don't specifically need an array, ie you're going to forEach
// the result, then can work with Set object
const setObj = new Set([...eventNamesArray, 'onReady', 'onError'])
setObj.forEach()
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check if array is empty or null or undefined 
Javascript :: jspdf converted pdf save to server 
Javascript :: scale an SVG gradient to your needs in react native 
Javascript :: importing svg into cra 
Javascript :: add class name in html 
Javascript :: conditional onclick react 
Javascript :: passport js local strategy response handling 
Javascript :: string methods javascript 
Javascript :: add an object to index 0 array js 
Javascript :: javascript set color in hex 
Javascript :: javascript check if consecutive array 
Javascript :: jquery slider value 
Javascript :: mongodb text search exact match 
Javascript :: vue is undefined vue 3 vue.use 
Javascript :: signed and unsigned integers in JavaScript 
Javascript :: date format in jquery 
Javascript :: Uncaught TypeError: theme.spacing is not a function 
Javascript :: angular countdown begin stop pause 
Javascript :: javascript function return boolean 
Javascript :: 2d array javascript 
Javascript :: json vs xml 
Javascript :: array.push 
Javascript :: performing query with sequelize includes 
Javascript :: chrome block javascript alert 
Javascript :: Return the highest number in Arrays in JavaScript 
Javascript :: HashRouter 
Javascript :: alertify js vue 
Javascript :: learn express 
Javascript :: Modal Dialogs in React 
Javascript :: array with object same keys 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =