Javascript Array Diff. Several of the built in array methods e g join slice indexof etc take into account the value of an array s length property when they re called. The logic to filter out is given through a callback function and each array element is passed to this function.
Function array diff array1 array2 return array1 filter function elm return array2 indexof elm 1. Other methods e g push splice etc also result in updates to an array s length property. Note that your original algorithm as well as tushar s answer won t work if the original array contains repeated items.
Like the name says filter method filters out elements from the array.
Write a javascript program to compute the union of two arrays. Venn diagram for the difference of two sets. The difference between arrays and objects. However the following will work.