
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove Duplicate Elements Within an Array in 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 ]
Advertisements