_.partition(collection, [predicate=_.identity])
创建一个分成两组的元素数组,第一组包含predicate
(断言函数)返回为 truthy(真值)的元素,第二组包含predicate
(断言函数)返回为 falsey(假值)的元素。predicate 调用1个参数:(value)。
const_=require('lodash'); varcar= [ { 'name': 'c1', "weight": 222.2 }, { 'name': 'c2', "weight": 212.2 }, { 'name': 'c3', "weight": 32.2 }, ] vararr=_.partition(car, function (o) { returno.weight>200; }); console.log(arr)