I want to quickly assign {x:1,y:2} to {row,col}, i.e. let row = objXY.x, let col = objXY.y
.
I know the destructuring assignment can do this
let {x,y} = objXY
But is there any way to do like this?
let {row,col} = objXY
I want to quickly assign {x:1,y:2} to {row,col}, i.e. let row = objXY.x, let col = objXY.y
.
I know the destructuring assignment can do this
let {x,y} = objXY
But is there any way to do like this?
let {row,col} = objXY
You can assign destructured properties to new variable names as described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Assigning_to_new_variable_names
For example
const obj = {x: 1, y: 2};
const {x: row, y: col} = obj;
console.log(row); // 1
console.log(col); // 2