Removing object properties with Lodash

后端 未结 8 1403
旧巷少年郎
旧巷少年郎 2021-02-02 05:30

I have to remove unwanted object properties that do not match my model. How can I achieve it with Lodash?

My model is:

var model = {
   fname: null,
   lna         


        
8条回答
  •  离开以前
    2021-02-02 05:53

    You can use _.omit() for emitting the key from a JSON array if you have fewer objects:

    _.forEach(data, (d) => {
        _.omit(d, ['keyToEmit1', 'keyToEmit2'])
    });
    

    If you have more objects, you can use the reverse of it which is _.pick():

    _.forEach(data, (d) => {
        _.pick(d, ['keyToPick1', 'keyToPick2'])
    });
    

提交回复
热议问题