当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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?

})

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: