Was it helpful?

Question

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

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

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 ]
raja
Published on 03-Oct-2020 19:01:39
Advertisements
Was it helpful?
Not affiliated with Tutorialspoint
scroll top