js 更改對象屬性名

來自:https://segmentfault.com/q/1010000011923504 侵刪segmentfault

 

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

將其中的CourseName更改成titlespa

      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)

修改爲功!code

相關文章
相關標籤/搜索