How to omit specific properties from an object in JavaScript

后端 未结 14 1476
无人共我
无人共我 2021-02-01 14:50

Is there a clean way to return a new object that omits certain properties that the original object contains without having to use something like lodash?

14条回答
  •  你的背包
    2021-02-01 15:40

    Sure, why not something like:

    var original = {
      name: 'Rory',
      state: 'Bored',
      age: '27'
    };
    
    var copied = Object.assign({}, original);
    delete copied.age;
    
    console.log(copied);
    

    https://jsfiddle.net/4nL08zk4/

提交回复
热议问题