It’s easier using Array.filter
:
var unique = arr.filter(function(elem, index, self) {
return index === self.indexOf(elem);
})
More Related Contents:
- Convert JSON to array in Javascript
- Creating a JavaScript global array with static elements?
- Array.prototype.fill() with object passes reference and not new instance
- JavaScript “new Array(n)” and “Array.prototype.map” weirdness
- Convert array to JSON
- Why can I add named properties to an array as if it were an object?
- Is the order of elements in a JSON list preserved?
- How to find if an array contains a specific string in JavaScript/jQuery?
- Sum JavaScript object propertyA values with the same object propertyB in an array of objects
- How to change value of object which is inside an array using JavaScript or jQuery?
- How might I extract the property values of a JavaScript object into an array?
- Sampling a random subset from an array
- Convert JavaScript array of 2 element arrays into object key value pairs
- Selecting last element in JavaScript array [duplicate]
- JavaScript flattening an array of arrays of objects
- Best way to convert string to array of object in javascript?
- How to create an array in JavaScript whose indexing starts at 1?
- How to check if a string array contains one string in JavaScript? [duplicate]
- MongoDB select where in array of _id?
- Remove duplicate objects from an array using javascript
- How can I use optional chaining with arrays and functions?
- How to remove duplicates from a two-dimensional array? [closed]
- Javascript – sorting array by multiple criteria
- Strange behavior of an array filled by Array.prototype.fill()
- What does the Array method `reduce` do?
- Group javascript array object by same key
- Array.of vs “[ ]”. When to use Array.of over “[ ]”?
- Array.push return pushed value?
- Declare an array in TypeScript
- Array of object deep comparison with lodash