0

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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

worked perfectly, thank you.(i'll accept the answer as soon as possible)
1

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.