1.
项目需求:需要给一个对象的所有属性名后面都加一个s,例如:person = { name:'芳华',age:12, sex:'女'}
变成person = { names:'芳华',ages:12, sexs:'女'}
注意要用[]把动态属性括起来
2.
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)
注意:第二种方法有bug,当修改的键名和键值一样时,全局修改会修改所有相同的值。