Lodash remove items recursively

前端 未结 6 734
难免孤独
难免孤独 2020-12-03 22:35

Given this JSON object, how does lodash remove the reach value from the objects?

{ 
    total: 350,
    SN1: { 
        reach: 200,
        enga         


        
6条回答
  •  Happy的楠姐
    2020-12-03 22:47

    _.mapValues(object, v => _.isObject(v)? _.omit(v, 'reach'): v)
    

    _.mapValues(object, [iteratee=_.identity])

    Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru iteratee. The iteratee is invoked with three arguments: (value, key, object).

    _.omit(object, [props])

    creates an object composed of the own and inherited enumerable string keyed properties of object that are not omitted.

提交回复
热议问题