Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove contents of an array from another array

I have two arrays

var array1 = new Array ["a", "b", "c", "d", "e"];
var array2 = new Array ["a", "c", "d"];

I want to remove elements of array2 from array1

Result ["b", "e"]

Is there anything like

array1 = array1.remove(array2)

Note I'm using jquery-1.9.1

like image 598
Okky Avatar asked Sep 25 '13 07:09

Okky


People also ask

How do you remove all elements of an array from another array in JavaScript?

Array elements can be deleted using the JavaScript operator delete . Using delete leaves undefined holes in the array. Use pop() or shift() instead.

How do you remove values from an array?

pop() function: This method is used to remove elements from the end of an array. shift() function: This method is used to remove elements from the start of an array. splice() function: This method is used to remove elements from the specific index of an array.


1 Answers

Try:

var diff = $(array1).not(array2).get();
like image 136
Kamil Avatar answered Sep 22 '22 14:09

Kamil