1

I have an object, that will have variable number of other objects in it. In other words I have a container Object, that has other children object in it. Children do have their own properties.

I need to find a number of children objects in it, for that I found two ways of doing it. I am interested which one is the best practice way.

First way:

var numberOfChildren = Object.keys(parentObject).length;

Second way:

var tempP = parentObject
            var count = 0;
            for (var p in tempP) {
                if (tempP.hasOwnProperty(p)) {
                    count++;
                }
                alert(count)
            }

Third Way:

var sizeofChildren= _.size(parentObject);

I have added the third way as well Ideas?

Emilly
  • 91
  • 7

0 Answers0