Home >Web Front-end >JS Tutorial >How to get the length of JSON field in JS

How to get the length of JSON field in JS

小云云
小云云Original
2018-03-08 16:09:492645browse

JS Get the code for the length of the JSON field. This article will mainly share it with you in the form of code

//JS 获得JSON 字典的长度的代码  
  
var jsonData = {"name":"txt1","name2":"txt2"};  
  
function getJsonLength(jsonData) {  
  
    var jsonLength = 0;  
  
    for (var item in jsonData) {  
  
        jsonLength++;  
  
    }  
  
    return jsonLength;  
  
}  
  
console.log("json对象的长度为:",getJsonLength(jsonData));

The above is the detailed content of How to get the length of JSON field 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