Lodash – difference method

  • Post author:
  • Post category:Lodash
  • Post comments:2 Comments
Lodash - difference method

Syntax Lodash difference method

_.difference(array, [values])

Lodash difference method Creates an array of array values not included in the other given arrays using SameValueZero for equality comparisons. The order and references of result values are determined by the first array.

Arguments

  • array (Array) โˆ’ The array to inspect.
  • [values] (…Array) โˆ’ The values to exclude.

Output

  • (Array) โˆ’ Returns the new array of filtered values.

Example

var _ = require('lodash');
var numbers = [1, 2, 3, 4];
var listOfNumbers = '';

listOfNumbers = _.difference(numbers, [2]);
console.log(listOfNumbers);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 1, 3, 4 ]

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply