Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the size of an array in an object

I would like some help with getting the size of an array inside an object:

var st = { "itema":{...},"itemb":[{"id":"s01","cd":"c01","dd":"d01",....}{"id":"s02","cd":"c02","dd":"d02",....}]} 

How would you get a count of the objects inside "itemb" (in this case 2)?

like image 226
meli Avatar asked May 02 '11 19:05

meli


People also ask

How do you get the length of of a array inside a object in JavaScript?

You can use any string as property name. But if the property is not a valid identifier, then you cannot use dot notation ( a.b ) to access it, you have to use bracket notation ( a['b'] ).

How do you find the size of an array in array?

We can find the size of an array using the sizeof() operator as shown: // Finds size of arr[] and stores in 'size' int size = sizeof(arr)/sizeof(arr[0]);

Does size () work on arrays?

Unlike the String and ArrayList, Java arrays do not have a size() or length() method, only a length property.


1 Answers

Javascript arrays have a length property. Use it like this:

st.itemb.length 
like image 93
Andrew Hare Avatar answered Sep 17 '22 07:09

Andrew Hare