
- 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 elements from array in JavaScript using includes() and splice()?
The includes() check whether array has a specific element, whereas splice() is used to add/remove items. Following is the code −
Example
deleteElementsFromArray = function(elements, ...values) { let elementRemoved = Array.from(values); for (var index = 0; index < elements.length; index++){ if (elementRemoved.includes(elements[index])){ elements.splice(index, 1); index--; } } return elements; } console.log(deleteElementsFromArray([80,90,56,34,79], 90, 34,79));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo69.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo69.js [ 80, 56 ]
- Related Articles
- How to remove elements using the splice() method in JavaScript?
- Remove elements from array using JavaScript filter - JavaScript
- If string includes words in array, remove them JavaScript
- Changing an array in place using splice() JavaScript
- Remove elements from a queue using Javascript
- Remove elements from a PriorityQueue using Javascript
- Remove elements from a Set using Javascript
- Remove elements from a Dictionary using Javascript
- How to remove blank (undefined) elements from JavaScript array - JavaScript
- Filter array with filter() and includes() in JavaScript
- How to remove duplicate elements from an array in JavaScript?
- Remove elements from a linked list using Javascript
- How to remove certain number elements from an array in JavaScript
- How to splice duplicate item in array JavaScript
- JavaScript Remove random item from array and then remove it from array until array is empty

Advertisements