So, I have this array with attributes and i want to get its' length. In this case the array length should be 2 since there are only 2 "items"
{"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]}
I've already tried exist.length
but it returns undefined
. How can i get its' length?
asked Jul 3, 2013 at 10:21
2 Answers 2
var myObj = {"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]};
var arrLength = myObj.items.length;
myObj.items
- is the array, myObj.items.length
- length of that array.
answered Jul 3, 2013 at 10:23
user2469791user2469791
1 Comment
Correia JPV
worked perfectly, thank you.(i'll accept the answer as soon as possible)
You're having an object
which one of it's properties with the name items
is an array
with the length of 2.
Try:
var data = {"items":[{"value":"2","valor":0,"name":"Limpeza"},
{"value":"6","valor":0,"name":"TECREMOVE"}]};
var len = data.items.length;
answered Jul 3, 2013 at 10:24
Comments
lang-js