1

Im trying to get the size of an array but every time the console say me undefined and don't know why.

.success(function (data) {
            console.log('Random-Suffix:' + suffix);
            $scope.builds = new X2JS().xml_str2json(data);

            var size  = $scope.builds.length;
            console.log('Size: ' + size);



            $timeout(function () {
                $scope.exampleLiveDataChange();
            }, 3000);
        })
2
  • What is output of console.log($scope.builds)? Commented Mar 31, 2015 at 8:48
  • Try console.log(typeof($scope.builds)) you will most probably see that $scope.builds is not an array ! You may then need to output it and look for your array inside it; Commented Mar 31, 2015 at 9:07

1 Answer 1

3

From what I read in the X2JS documentation:

<instance>.xml_str2json - Convert XML specified as string to JSON

Maybe builds is not an array, but an object. If the object contains an array like this one:

var test = {one : 'one' , two : [1,2,3]};

If you do:

test.length;

You get:

undefined

If you do:

test.two.length;

Then you get:

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

2 Comments

Yeah, you are right, thanks. Do you know if is there a way to get the size of an array inside the object?
Yeah, it's easy. What is the structure of the object?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.