SHARE
TWEET

Untitled

a guest Sep 16th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Method 1
  2. function removeDuplicates(arr) {
  3.   let obj = {};
  4.   let len = arr.length;
  5.  
  6.   for (let index = 0; index < len; index++) {
  7.     let val = arr[index];
  8.     obj[val] = val;
  9.   }
  10.  
  11.   return Object.values(obj);
  12. }
  13.  
  14. console.log(removeDuplicates([21, 15, 0,-1, 2, 21, 15, 9, 7, 6]));
  15. //[0, 2, 6, 7, 9, 15, 21, -1]
  16.  
  17. //Method 2
  18. function removeDuplicates2(arr) {
  19.   return [...new Set(arr)];
  20. }
  21.  
  22. console.log(removeDuplicates2([21, 15, 0,-1, 2, 21, 15, 9, 7, 6]));
  23. //[21, 15, 0, -1, 2, 9, 7, 6]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top