Lodash – intersectionBy method

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

Syntax Of Lodash intersectionBy method

_.intersectionBy([arrays], [iteratee=_.identity])

This Lodash intersectionBy method is like _.intersection except that it accepts iteratee which is invoked for each element of each array to generate the criterion by which they’re compared.

Arguments

  • [arrays] (…Array) โˆ’ The arrays to inspect.
  • [iteratee=_.identity] (Function) โˆ’ The iteratee invoked per element.

Output

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

Example

var _ = require('lodash');
var numbers = [1.7, 2.4, 3.6, 4.2];
var listOfNumbers = '';

listOfNumbers = _.intersectionBy(numbers, [1.3, 2.2], Math.floor);
console.log(listOfNumbers);

listOfNumbers = _.intersectionBy([{ 'x': 4 }, { 'x': 1 }], [{ 'x': 4 }], 'x');
console.log(listOfNumbers);

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

Command

\>node tester.js

Output

[ 1.7, 2.4 ]
[ { x: 4 } ]

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply