Lodash - uniq 方法
语法
_.uniq(array)
使用 SameValueZero 进行相等性比较,创建一个无重复项的数组版本,其中仅保留每个元素的第一次出现。结果值的顺序由它们在数组中出现的顺序决定。
参数
array (数组) − 要检查的数组。
输出
(数组) − 返回新的无重复项数组。
示例
var _ = require('lodash');
var numbers = [1, 2, 2, 4]
var result = _.uniq(numbers);
console.log(result);
将上述程序保存在 tester.js 中。运行以下命令以执行此程序。
命令
\>node tester.js
输出
[ 1, 2, 4 ]
lodash_array.htm
广告