- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - intersectionWith method
Syntax
_.intersectionWith([arrays], [comparator])
This method is like _.intersection except that it accepts comparator which is invoked to compare elements of arrays. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
Arguments
[arrays] (...Array) − The arrays to inspect.
[comparator] (Function) − The comparator 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 = _.intersectionWith([{ 'x': 4 }, { 'x': 1 }], [{ 'x': 4 }], _.isEqual); console.log(listOfNumbers);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ { x: 4 } ]
lodash_array.htm
Advertisements