Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 ]
Advertisements
