My javascript code like this :
var data= {product_id: 4, name: 'nike'}
console.log(data)
var dataNew = data
dataNew.id = 1
console.log(dataNew)
Demo is like this : https://jsfiddle.net/oscar11/69dw8dv1/
I append value in the object like that
The result of console.log(data) and console.log(dataNew) is there exist id
I want var data is no id
So there is only var dataNew that has id
How can I do it?
delete data.idbut this would delete the property fromdataNewtoo. You need to clone the object before doing that.const dataNew = Object.assign({}, data)