javascript to remove duplicates from an array
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'unique = [...new Set(arr)]; // where arr contains duplicate elementsuniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)uniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})
Also in JavaScript:
- substring javascript
- mocha supertest
- vscode pylint disable Module name doesn't conform to snake_case naming style
- how to flatten array in javascript using foreach loop
- javascript getdate
- moment format datetime postgresql
- react hide scrollbar
- js replace blogger thumb
- joudyhallo
- javascript function return boolean
- js array return only certain positions
- remove disabled attribute javascript
- js explode equivalent
- js array map
- angular redirect to external url
- react google maps get map center
- steam roll array javascript
- jquery data
- ajax file upload from modal
- bot prefix discord.js
- location.reload sweetalert
- vuejs send required props to dynamic component
- how to integrate vuejs with nodejs and express
- edit onclick event