godzo101 godzo101 - 1 year ago 149
AngularJS Question

get the object length in angular is undefined

How can I get the object length ?

In console my object looks like this:

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

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


Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download