vuejs copying data object and removing property will remove the property from original object as well vuejs copying data object and removing property will remove the property from original object as well vue.js vue.js

vuejs copying data object and removing property will remove the property from original object as well


You need to take a copy of your data by cloning it. There are various ways of cloning the data, I would recommend using lodash's function, cloneDeep

postDataCopy = _.cloneDeep(postData)

Then you can modify postDataCopy as you like without modifying the original.


this is because in javascript objects are copied-by-reference which means though you are changing postData which actually is referencing to original address that holds the data i.e. rows. you can do this

postData = JSON.parse(JSON.stringify(rows))


You need to make a copy of your referenced variable.

// ES6let copiedObject = Object.assign({}, originalObject)