
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Remove same values from array containing multiple values JavaScript
Let’s say the following is our array with similar values −
const listOfStudentName = ['John', 'Mike', 'John', 'Bob','Mike','Sam','Bob','John'];
To remove similar values from array, use the concept of set(). Following is the code −
Example
const listOfStudentName = ['John', 'Mike', 'John', 'Bob','Mike','Sam','Bob','John']; console.log("The value="+listOfStudentName); const doesNotContainSameElementTwice = [...new Set(listOfStudentName)]; console.log("The Array="); console.log(doesNotContainSameElementTwice)
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo42.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo42.js The value=John,Mike,John,Bob,Mike,Sam,Bob,John The Array= [ 'John', 'Mike', 'Bob', 'Sam' ]
- Related Articles
- Remove duplicates from array with URL values in JavaScript
- JavaScript Array: Checking for multiple values
- How to remove falsy values from an array in JavaScript?
- MongoDB query to pull multiple values from array
- Find and return array positions of multiple values JavaScript
- How to remove duplicate property values in array – JavaScript?
- Remove '0','undefined' and empty values from an array in JavaScript
- How to find elements of JavaScript array by multiple values?
- Extract unique values from an array - JavaScript
- How to check whether multiple values exist within a JavaScript array
- Fetch alternative even values from a JavaScript array?
- Select random values from an array in JavaScript?
- Remove all values from Java LinkedHashMap
- Group values on same property - JavaScript
- JavaScript: Combine highest key values of multiple arrays into a single array

Advertisements