如何访问此对象内部数组的长度

How do you access the length of the array inside of this object?

本文关键字:数组 内部 对象 何访问 访问      更新时间:2023-09-26

我有一个看起来像这样的对象:

[ { _id: 507351805725f3457b000055,
    audioFiles: [ [Object], [Object] ] } ]

我想访问audioFiles的length属性,这样我就可以循环浏览它的内容。然而,我一直得不到定义或1。有人能告诉我正确的路吗?

以下是我迄今为止所做的尝试(请注意,对象变量名为audios)。

audios.audioFiles.length
audios.length
audios[0].audioFiles.length

它是:

> audios[0].audioFiles.length
2

您可以使用Chrome的Web Inspector或Firefox上的Firebug自行测试。

使用audios[0].audioFiles.length