godzo101 godzo101 - 4 months ago 43
AngularJS Question

Get the object length in angularjs is undefined

How can I get the object length ?

In console my object looks like this:

Object {2: true, 3: true, 4: true}

.length will give me undefined. I just want to get the results = 3 ,for this case.


var keys = Object.keys(objInstance);
var len = keys.length;

Where len is your "length."

There may be circumstances I haven't thought of where this doesn't work, but it should do what you need, given your example.