How to clone a Javascript Array of Objects?

后端 未结 7 1340
一向
一向 2020-12-09 19:10

I have a result set which is an array of objects. I need to clone this so I can make changes to it, without touching the original data.

var data = w2ui.grid.         


        
7条回答
  •  粉色の甜心
    2020-12-09 20:06

    ES6:

    If you want to have cloned objects too, you have to spread array and objects:

    const newArrayOfObjects = [
      ...originalArrayOfObject
    ].map(i => ({ ...i}));
    

提交回复
热议问题