I have a JSON object whose key's are renamed with the help of map() function. I am not understanding the working of it. Can someone explain how the key names are renamed?
This is my code for renaming JSON keys:
let arr = [
{
STUDENT_ID: "1",
STUDENT_NAME: "abc"
},
{
STUDENT_ID: "2",
STUDENT_NAME: "xyz"
}
]
let renamedArr = arr
.map(({ STUDENT_ID: studentId, STUDENT_NAME: studentName }) => ({
studentId,
studentName
}));
console.log({ renamedArr })
This is my output:
[
{
"studentId": "1",
"studentName": "abc"
},
{
"studentId": "2",
"studentName": "xyz"
}
]