Home > Article > Web Front-end > Capitalizing the first letter of the object key value in json in js
function toUpperCase(jsonObj) { if(typeof(jsonObj)=='object'){ for (var key in jsonObj){ jsonObj[key.substring(0,1).toUpperCase()+key.substring(1)] = jsonObj[key]; delete(jsonObj[key]); } return jsonObj; } return data; }var res; var _data = {"myKey":"myValue"}; res = toUpperCase(_data); console.log(res);//{MyKey: "myValue"}console.log(JSON.stringify(res));//{"MyKey":"myValue"}
The above is the detailed content of Capitalizing the first letter of the object key value in json in js. For more information, please follow other related articles on the PHP Chinese website!