Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using AngularJS to render html page doing ajax call, which returns json file.

How to get count of id's in below JSON using angularjs?

[{"id":1,"Name":"Apple"},
 {"id":2,"Name":"Mango"},
 {"id":3,"Name":"Banana"}
 {"id":4,"Name":"Coconut"}
 {"id":5,"Name":"pineaple"}
 {"id":6,"Name":"Orange"}
 {"id":7,"Name":"Guava"}]
share|improve this question
3  
possible duplicate of Length of Javascript Object (ie. Associative Array) –  domokun Jul 4 at 13:17
    
This is so basic that you could have found it in 30 seconds straight. It's not even Angular... –  domokun Jul 4 at 13:18
1  
@domokun it is a regular array not an object –  Ilan Frumer Jul 4 at 13:19
    
Even simpler... –  domokun Jul 4 at 13:21
2  
did you try Array.length? –  charlietfl Jul 4 at 13:21

1 Answer 1

You don't need Angular to get the length of that.

In this case, your parsed JSON is a simple array, you can get the length with:

obj.length

assuming that obj contains your parsed JSON as such:

var obj = [{"id":1,"Name":"Apple"},
{"id":2,"Name":"Mango"},
{"id":3,"Name":"Banana"}
{"id":4,"Name":"Coconut"}
{"id":5,"Name":"pineaple"}
{"id":6,"Name":"Orange"}
{"id":7,"Name":"Guava"}]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.