I am trying to swap two object values in JavaScript using the [] = []
method, but my below code fails with an error saying "message": "Uncaught TypeError: Cannot set property '9' of undefined",
let dataObj={"reg_price":2, "reg_price_alt":5, "ex":9}
console.log("before: ", dataObj)
[dataObj.reg_price, dataObj.ex] = [4, 5];
console.log("after: ", dataObj)
Is there some syntax I'm missing? I don't understand why this simple code does not work.