_.difference
Similar to without, but returns the values from array that are not present in the other arrays.
- // Underscore/Lodash
- console.log(_.difference([1, 2, 3, 4, 5], [5, 2, 10]))
- // output: [1, 3, 4]
- // Native
- var arrays = [[1, 2, 3, 4, 5], [5, 2, 10]];
- console.log(array.reduce(function(a, b) {
- return a.filter(function(value) {
- return !b.includes(value);
- });
- })));
- // output: [1, 3, 4]
- // ES6
- let arrays = [[1, 2, 3, 4, 5], [5, 2, 10]];
- console.log(arrays.reduce((a, b) => a.filter(c => !b.includes(c))));
- // output: [1, 3, 4]
Browser Support for Array.prototype.reduce()
✔ | ✔ | 3.0 ✔ | 9.0 ✔ | 10.5 ✔ | 4.0 ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .