I want to replace a variable in an object array with another name,
let arr={name:'ash', id:2}
I want to replace it as arr = {newname:'ash', id:2}
There are two options:
1.
let name = arr.name
arr = {...arr, name: null, newname:name}
You can use omit
function from lodash
library, and this option is better. Here is docimentation of omit function
let arr={name:'ash', id:2}
let newname = arr.name;
delete arr.name
arr['newname'] = newname
console.log(arr)
You can use a variable to store the value of name ,then use Object operator delete the key of name