Home > Article > Web Front-end > How to get the length of json array in js
What I bring to you this time is how to get the length of the jsonarray in js. We know that json does not have the .lengthattribute. How to get the length of the json array? This article will give you a good analysis.
The problem I encountered is this: In the page at the end of ***.jsp, the json data passed to me by the backend is an array, and then I need to get the array length in the second array contacts, Then Baidu discovered json does not have a .length attribute. How to do it?
Since the json object does not have a length attribute, what if you want to know its length?
var jslength=0; for(var js2 in json){ jslength++; }
Write this code into a method and call it later:
function getJsonLength(jsonData){ var jsonLength = 0; for(var item in jsonData){ jsonLength++; } return jsonLength; }
I believe you have mastered the method after reading the above introduction. Please pay attention to php for more exciting information. Chinese website Other related articles!
Related reading:
How to customize the console object during the use of JS
How to download and install nodejs
Summary of the front-end js framework and explanation of its uses
The above is the detailed content of How to get the length of json array in js. For more information, please follow other related articles on the PHP Chinese website!