SoFunction
Updated on 2025-04-06

js method to get the number of json elements

This article example describes how to obtain the number of json elements by js. Share it for your reference. The specific implementation method is as follows:

Copy the codeThe code is as follows:
<script>
var keleyijson={"plug1":"myslider","plug2":"zonemenu","plug3":"javascript"}

function JSONLength(obj) {
var size = 0, key;
for (key in obj) {
if ((key)) size++;
}
return size;
};
(The number of elements of the "json object is: "+JSONLength(keleyijson));
</script>

The effects are as follows:

The number of elements of a json object is: 3

PS: Regarding json operation, here are some practical json online tools for your reference:

Online JSON code verification, inspection, beautification and formatting tools:
http://tools./code/json

JSON online formatting tool:
http://tools./code/jsonformat

Online XML/JSON mutual conversion tool:
http://tools./code/xmljson

json code online formatting/beautification/compression/editing/converting tools:
http://tools./code/jsoncodeformat

Online json compression/escaping tools:

http://tools./code/json_yasuo_trans

C language style/HTML/CSS/json code formatting and beautification tools:
http://tools./code/ccode_html_css_json

I hope this article will be helpful to everyone's JavaScript programming.