Last active
November 15, 2022 17:13
-
-
Save telekosmos/3b62a31a5c43f40849bb to your computer and use it in GitHub Desktop.
Remove duplicates from js array (ES5/ES6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var uniqueArray = function(arrArg) { | |
return arrArg.filter(function(elem, pos,arr) { | |
return arr.indexOf(elem) == pos; | |
}); | |
}; | |
var uniqEs6 = (arrArg) => { | |
return arrArg.filter((elem, pos, arr) => { | |
return arr.indexOf(elem) == pos; | |
}); | |
} | |
var test = ['mike','james','james','alex']; | |
var testBis = ['alex', 'yuri', 'jabari']; | |
console.log(uniqueArray(test.concat(testBis))); |
gevera
commented
Nov 15, 2022
•
Hi @gevera
Beware of problems when using JSON.stringify and JSON.parse with:
- number: https://github.com/josdejong/lossless-json
- date: https://stackoverflow.com/questions/31096130/how-to-json-stringify-a-javascript-date-and-preserve-timezone
Being bitten more than once... 🤕
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment