Lodash教程

Lodash intersectionWith method

语法:

_.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).

参数

[arrays] (...Array) − The arrays to inspect. [comparator] (Function) − The comparator invoked per element.

输出:

(Array) − Returns the new array of intersecting values.

实例:

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.

命令:

\>node tester.js

输出:

[ { x: 4 } ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4