How to change obj key, change object key
The implementation is shown in figure (code snippet below)
Attach the code block:
let obj = {
mingzi: 'Joe'.nianling: 18.friend: [{
mingzi: 'bill'.nianling: 19
},
{
mingzi: 'Cathy'.nianling: 20}}]const map = {
mingzi: "name".nianling: "age",}const newObj = JSON.parse(
JSON.stringify(obj).replace(
/mingzi|nianling/gi.matched= > map[matched])
)
console.log(newObj)
Copy the code