How to redundantly remove duplicate elements within an array – JavaScript?


Let’s say the following are our array elements −

10,20,10,50,60,10,20,40,50

To remove duplicate elements, use … new Set().

Example

Following is the code −

var arrayWithNoDuplicateNumbers = [...new Set([10,20,10,50,60,10,20,40,50])];
console.log("No Duplicate values=")
console.log(arrayWithNoDuplicateNumbers);

To run the above program, use the following command −

node fileName.js.

Here, my file name is demo243.js.

Output

The output is as follows −

PS C:\Users\Amit\javascript-code> node demo243.js
No Duplicate values=
[ 10, 20, 50, 60, 40 ]

Updated on: 03-Oct-2020

164 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements