wwli
wwli

Reputation: 2681

Get length of array in object with unknown key

I would like to get length of the array in this object:

obj = {'2012-08-08':[1,2,5,8]}

I understand we can get length like this:

obj['2012-08-08'].length

But if it is not known the name of the key how we get the length of the array?

Say I have a loop:

_.each(dates, function(date){
     //each date is like the above javascript object, how to  get the length of the array?

})

Upvotes: 0

Views: 162

Answers (1)

Jacob
Jacob

Reputation: 78848

You have a date parameter in your call to each. Just call date.length.

Upvotes: 2

Related Questions