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