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

How to get the length of JSON field in JS

小云云
Release: 2018-03-08 16:09:49
Original
2614 people have browsed it

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));
Copy after login

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!

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