Filtering object properties based on value

前端 未结 7 783
孤独总比滥情好
孤独总比滥情好 2020-12-14 16:40

Is there some elegant way of filtering out falsey properties from this object with lodash/underscore? Similar to how _.compact(array) removes falsey elements fr

7条回答
  •  忘掉有多难
    2020-12-14 17:16

    From lodash 4, we can use pickBy() to get only the value equal to true.

    const active = _.keys(_.pickBy(object));
    

提交回复
热议问题