How to use set() Method In Javascript
This method sets a new object type with ES6 (ES2015) that allows you to create collections of unique values.
Example: In this example, we will see the use of the set() method.
let arr = ["apple", "mango", "apple",
"orange", "mango", "mango"];
function removeDuplicates(arr) {
return [...new Set(arr)];
}
console.log(removeDuplicates(arr));
Output:
["apple", "mango", "orange"]
How to Remove duplicate elements from array in JavaScript ?
In this article, we will discuss the methods to remove duplicate elements from a Javascript array. There are various methods to remove duplicates in the array.
These are the following ways:
Table of Content
- Using filter() Method
- Using set() Method
- Using forEach() Method
- Using reduce() Method
- Using indexOf() Method
- Using a third-party library
- Using Map
Below all the methods are described with proper examples:
Contact Us