My data object in Vue is structured as follows:
rows[
0 {
title: "my title",
post: "my post text",
public: false,
info: "some info"
},
1 {
title: "my title",
post: "my post text"
public: true,
info: "some info"
},
2 {
title: "my title",
post: "my post text"
public: false,
info: "some info"
}
]
To prepare this object before sending it to the backend, I make a copy and remove certain properties if necessary using the following method:
var postData = this.rows;
postData.forEach(function(o) {
if (o.public === true) {
delete o.info;
}
});
var uploadData = {};
uploadData.blogpost = postData;
axios({
method: 'post',
url: myUrl,
responseType: 'json',
data: uploadData
})
The issue arises when delete o.info;
also removes the property from my root vm data. I am puzzled by this behavior as I clearly copied the data into a new variable. How can I solve this problem and remove specific object properties without affecting my root vm data in Vue?