i have lodash map function has empty value in important property of given key, , in case i'd remove key result entirely. how do that?
tried if (_.isempty(key.thing)) { delete key } didn't work - broke app.
you can use reduce function , filter empty values there.
_.reduce(yourarray, function(result, currentitem) { var itemaftersomeoperations; if (!_.isempty(currentitem.thing)) { //here can operations in _.map handler function //and push updated item after operations in resulted array itemaftersomeoperations = someoperationonitemandreturnnewvalue(currentitem); result.push(itemaftersomeoperations); } return result; }, []); you don't need delete key, since _.map _.reduce return new array items like. please, keep in mind map, filter, find etc can implemented reduce.
Comments
Post a Comment