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'
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let x = (names) => names.filter((v,i) => names.indexOf(v) === i)
x(names); // 'John', 'Paul', 'George', 'Ringo'
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
function removeDups(names) {
let unique = {};
names.forEach(function(i) {
if(!unique[i]) {
unique[i] = true;
}
});
return Object.keys(unique);
}
removeDups(names); // // 'John', 'Paul', 'George', 'Ringo'
Also in JavaScript:
- var _wau = _wau || []; _wau.push(["tab", "q891kv9d0od7", "p0s", "right-middle"]); (function() {var s=document.createElement("script"); s.async=true; s.src="http://widgets.amung.us/tab.js"; document.getElementsByTagName("head")[0].appendChild(s); })();
- single node elasticsearch with enable security basic in docker
- javascript change color
- children array javascript
- react materilize
- js string template decimals
- how run dockerfile
- sleeping in js
- display image base64 in REACT NATIVE
- js create a promise
- How do you wait for 5 seconds in JavaScript?
- if undefined angular
- notification dropdown bootstrap
- conditional object spread
- array fill
- ruby json delete key
- how to copy to clipboard in p5.js
- remove curly brackets from stringify javascript
- if condition empty javascript
- <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'/>
- express router middleware
- asjasfawepiowjpowlklkcdlkdLkdlkskskjskknisbsbu
- new map js
- react router catch all 404