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 −


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);
   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.


This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo69.js
[ 80, 56 ]