Home  >  Article  >  Web Front-end  >  Capitalizing the first letter of the object key value in json in js

Capitalizing the first letter of the object key value in json in js

一个新手
一个新手Original
2017-09-22 09:56:202918browse


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn