如何将数据库读取的json数组格式的数据通过js将key由连接符转为驼峰式?

废话不多说先上代码

           var userlist =[];
           var arr = response.data,//获取到的json数据
                     item;
			
           for(var i=0,length =arr.length;i

最后给大家看一下效果。

转换之前的json格式的数据:

[
{
USER_NAME:"赵四",
USER_AGE:23,
USER_GENDER:"男"
},
{
USER_NAME:"王五",
USER_AGE:24,
USER_GENDER:"男"
},
{
USER_NAME:"小红",
USER_AGE:19,
USER_GENDER:"女"
},...
]

转换之后的:

[
{
userName:"赵四",
userAge:23,
userGender:"男"
},
{
userName:"王五",
userAge:24,
userGender:"男"
},
{
userName:"小红",
userAge:19,
userGender:"女"
},...
]

 

你可能感兴趣的:(JavaScript)