3.10 difference

3.10.1语法

_.difference(array, *others)

3.10.2说明

类似于without,但返回的值来自array参数数组,并且不存在于other 数组.

3.10.3示例

示例一,others传入的值可以是数组,可以是一个也可以是多个

var res = _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
console.log(res);
//=> [1, 3, 4]

var res = _.difference([1, 2, 3, 4, 5], [2, 10],[5,1]);
console.log(res);
//=> [3, 4]

示例二,others可以传入多个数字

var res = _.difference([1, 2, 3, 4, 5], 5, 2, 10);
console.log(res);
//=> [1, 3, 4]

与without相比较,without的others只能传入多个数字,不能传数组。

var res = _.without([1, 2, 3, 4, 5], 5, 2, 10);
console.log(res);
//=> [1, 3, 4]

var res = _.without([1, 2, 3, 4, 5], [5, 2, 10]);
console.log(res);
//=> [1, 2, 3, 4, 5]