ES6

    function removeDuplicates(arr) {
      let x = new Set(arr);
      return [...x];
    }

filter

    function removeDuplicates(arr) {
      return arr.filter((el, index, self) => {
        return self.indexOf(el) === index
      })
    }

排序后去重(使用新数组)

    function removeDuplicates(nums) {
      nums.sort();
      let tmp = [nums[0]];
      for (let i = 1; i < nums.length; i++) {
        if (nums[i] !== tmp[tmp.length - 1]) {
          tmp.push(nums[i]);
        }
      }
      return tmp
    }

leetcode 26. Remove Duplicates from Sorted Array

    function removeDuplicates(nums) {
      var i = 0;
      for (var j = 1; j < nums.length; j++) {
        if (nums[j] != nums[i]) {
          i++;
          nums[i] = nums[j];
        }
      }
      return i + 1;
    };