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)?
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'] ).
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]);
Unlike the String and ArrayList, Java arrays do not have a size() or length() method, only a length property.
Javascript arrays have a length property. Use it like this:
st.itemb.length
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With