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是一个能够帮助我们更方便的对数组进行各种操作的javascript工具库
文档:http://lodashjs.com/docs/#_findindexarray-predicate_identity-thisarg