Other answers will include (at least) two loops along the length of the object. Do you really want to _.reduce:
_.reduce({ one : 1, two : 2, three : 3 }, function ( out, num, key ) {
if ( key === 'one' || key === 'two' ) {
out.push( num );
}
return out;
}, []);
This will give you your answer, compressed as you like, just one loop through your object.
source
share