
- 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 all occurrences of a multiple occurring element in an array in JavaScript
We are required to write a JavaScript function that takes in an array of literal values.
The array might contain some repeating values.
Our function should remove all the values from the array that are repeating. We are required to remove all instances of all such elements.
Example
The code for this will be −
const arr = [1, 2, 3, 2, 4]; const removeAllInstances = (arr = []) => { filtered = arr.filter(val => { const lastIndex = arr.lastIndexOf(val); const firstIndex = arr.indexOf(val); return lastIndex === firstIndex; }); return filtered; }; console.log(removeAllInstances(arr));
Output
And the output in the console will be −
[ 1, 3, 4 ]
- Related Articles
- Golang Program To Remove All Occurrences Of An Element In An Array
- Swift Program to Remove All Occurrences of an Element in an Array
- Find all occurrences of a word in array in JavaScript
- Iterating through an array, adding occurrences of a true in JavaScript
- If the element repeats, remove all its instances from array in JavaScript
- How do I remove a particular element from an array in JavaScript
- Match multiple occurrences in a string with JavaScript?
- Unique number of occurrences of elements in an array in JavaScript
- Remove element from array referencing spreaded array in JavaScript
- Finding all duplicate numbers in an array with multiple duplicates in JavaScript
- Count occurrences of an element in a list in Python
- How to replace all occurrences of a string in JavaScript?
- How to remove every Nth element from an array JavaScript?
- How to count number of occurrences of repeated names in an array - JavaScript?
- How to remove an element from an array in Java

Advertisements