1

I'm using a GET method to view a json file as follows.

$scope.train = function () {

            var url = 'http://localhost/heart/api/restApiController/dataset.json';

            $http({
                method: 'GET',
                url: url


            }).then(function (data) {

            });


        };

Now I want to count numberof objects in the json file.how can I do it?

log of data

Object {data: Array[5], status: 201, config: Object, statusText: "Created"}
config:Object
data:Array[5]
headers:(d)
status:201
statusText:"Created"

So there are 5 objects in this array.how can I get this value 5 from AngularJS code?

1

1 Answer 1

4

You can simply use the standard length

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

2 Comments

so if I want to count the objects with specific values, how can I do it? Ex: I want to count the objects with weight: "2" How to do this?
As you are using angularjs, you could use filter and then length on the returned array, see filter

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.