js 更改对象属性名

来自:https://segmentfault.com/q/1010000011923504 侵删

 

[
    {
        "Id":"3972679ef2c04151972b376dd88e6413",
        "T_CourseId":"7a4494aae1804d3e94094583249750fe",
        "CourseName":"英语",
        "Code":"english"
    },
    {
        "Id":"5665d803e7994b26a56c6287d12c2090",
        "T_CourseId":"75761ad2ce23498c9f9db134ab844aec",
        "CourseName":"药物化学",
        "Code":"ywhx"
    }
]

将其中的CourseName更改为title

      var aaa = [
    {
        "Id":"3972679ef2c04151972b376dd88e6413",
        "T_CourseId":"7a4494aae1804d3e94094583249750fe",
        "CourseName":"英语",
        "Code":"english"
    },
    {
        "Id":"5665d803e7994b26a56c6287d12c2090",
        "T_CourseId":"75761ad2ce23498c9f9db134ab844aec",
        "CourseName":"药物化学",
        "Code":"ywhx"
    }
]
   var bbb= JSON.parse(JSON.stringify(aaa).replace(/CourseName/g,"title"));
    console.log(bbb)

修改成功!

posted @ 2018-12-10 17:42  abcByme  阅读(23142)  评论(2编辑  收藏  举报