Home > Web Front-end > JS Tutorial > body text

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

一个新手
Release: 2017-09-22 09:56:20
Original
2932 people have browsed it


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"}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template