Removing object properties with Lodash

后端 未结 8 1519
旧巷少年郎
旧巷少年郎 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:52

    Here I have used omit() for the respective 'key' which you want to remove... by using the Lodash library:

    var credentials = [{
            fname: "xyz",
            lname: "abc",
            age: 23
    }]
    
    let result = _.map(credentials, object => {
                           return _.omit(object, ['fname', 'lname'])
                       })
    
    console.log('result', result)
    

提交回复
热议问题