var aaa = [ { "Id":"3972679ef2c04151972b376dd88e6413", "T_CourseId":"7a4494aae1804d3e94094583249750fe", "CourseName":"英语", "Code":"english" }, { "Id":"5665d803e7994b26a56c6287d12c2090", "T_CourseId":"75761ad2ce23498c9f9db134ab844aec", "CourseName":"药物化学", "Code":"ywhx" } ]
怎么使用js
高效的将其中的CourseName
更改为title
,得到结果如下:
var bbb= JSON.parse(JSON.stringify(aaa).replace(/CourseName/g,"title")); console.log(bbb)
或者:
arr.forEach(function(item){ item.title = item.CourseName; delete item.CourseName; })