godzo101 godzo101 - 4 months ago 35
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.


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.