`_.difference` function on array using JavaScript Library underscore.js ( #shorts )

1 year ago
1

Hi Friends,

`_.difference` function on array using JavaScript Library underscore.js

`_.difference` is also utility function in Underscore.js library that allows you to create a new array that contains all the elements from one array that are not present in one or more other arrays.

In below example, we have three arrays `numbers1`, `numbers2` and `numbers3`, and we use `_.difference` to create a new array that contains all the elements from `numbers1` that are not present in any of the other arrays. The resulting `newNumbers` array contains the element 1, because it is the only element in `numbers1` that is not also in `numbers2` or `numbers3`.

Note: `_.difference` does not modify the original arrays, it returns a new array with the excluded values.

// syntax
_.difference(array, [others])

// example
var numbers1 = [1, 2, 3];
var numbers2 = [2, 3, 4];
var numbers3 = [3, 4, 5];
var newNumbers = _.difference(numbers1, numbers2, numbers3);

console.log(newNumbers); // [1]

#javascript #under #score #underscore #underscorejs #difference #underscoredifference #differencefunction #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official

Loading comments...