The _.difference() function returns the values of array that are not present in the other arrays. If element is present in array then this element will not be included in the resultant array. This is because it takes difference of the second array and first array.
_.difference( array, *others )
Parameters: This function accepts two parameters as mentioned above and described below:
- array: This parameter is used to hold the array elements.
- others: It is an array whose elements need to be deleted.
Return value: This function returns an array which contains elements of the first array which are not in the second array.
Passing a list of numbers to _.difference() function: The ._difference() function takes the element from the list one by one and checks if that element is present in the second array or not. If it is present then it simply ignores the element otherwise add the elements in the resultant array.
Passing false values to the _.difference() function: Passing the false values like null, undefined, false, “” (empty string) then the _.difference() function will work in the same way. If any of the false values are present in the first array but not present in the second array then it will be included in the resultant array.
Passing a set of strings to the _.difference() function: Passing the set of strings which contains words inside “” then the _.difference() function will work in the same way. If any of the these string values are present in the first array but not present in the second array then it will be included in the resultant array.
Passing two arrays which have the same elements to the _.difference() function: Passing the first and the second array having the same elements then all the elements during the check operation will be ignored. And hence the resultant array will be empty.
Note: These commands will not work in Google console or in Firefox as for these additional files need to be added which they didn’t have added. So, add the given links to your HTML file and then run them.
- Difference between “!==” and “==!” in PHP
- Difference between JSP and ASP
- Web 1.0, Web 2.0 and Web 3.0 with their difference
- Difference between ASP and ASP.NET
- Difference Between HTML and ASP
- What is the difference between the | and || or operator in php?
- Difference between array() and  in PHP
- Difference between ReactJS and Vue.js
- What is the difference between MySQL, MySQLi and PDO?
- Difference between Web Browser and Web Server
- Difference between VueJS and AngularJS
- Difference between REST API and SOAP API
- Difference between innerText and innerHTML
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.