lodash链式使用

时间:2021-05-12 04:06:43

chain

var _ = require('lodash');
var user1 = {
	name: 'zhangsan',
	height: 180,
	weight: 120
};
var user2 = {
	name: 'lisi',
	height: 180,
	weight: 130
};
var user3 = {
	name: 'zhangsan',
	height: 180,
	weight: 131
};

var users = [user1, user2, user3];
var result = _.chain(users).filter({name: 'zhangsan'}).uniq('name').pluck('weight').value();
console.log(result);

lodash链式使用

总结:lodash是一个能够帮助我们更方便的对数组进行各种操作的javascript工具库

文档:http://lodashjs.com/docs/#_findindexarray-predicate_identity-thisarg