Created
February 27, 2018 13:39
-
-
Save monjer/499dc1f4fe5f30dba0f8a762c6956eeb to your computer and use it in GitHub Desktop.
JS remove duplicate element in array
This file contains hidden or 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
| function removeDup(arr){ | |
| return [...new Set(arr)]; | |
| } | |
| function removeDup(arr){ | |
| return Array.from(new Set(arr)); | |
| } | |
| function removeDup(arr){ | |
| let array = []; | |
| arr.forEach(function(item){ | |
| if(array.indexOf(item) === -1){ | |
| array.push(item); | |
| } | |
| }); | |
| return array; | |
| } | |
| function removeDup(arr){ | |
| let array = []; | |
| arr.forEach(function(item){ | |
| if(array.indexOf(item) === -1){ | |
| array.push(item); | |
| } | |
| }); | |
| return array; | |
| } | |
| function removeDup(arr){ | |
| var res = arr.filter(function(item, index, array){ | |
| return arr.indexOf(item) === index; | |
| }) | |
| return res; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment