javascript - 为什么 array[length] 返回列表的第一个元素?

标签 javascript arrays

<分区>

据我所知,可以通过使用

返回数组的长度

array.length

数组["长度"]

但像这样省略引号

数组[长度]

将返回数组的第一个元素 这是实际的代码: 变量列表 = [5, 7, 10];然后在控制台 list[length] 返回 5,不,我在窗口中没有 iframe 或框架,所以 window.length 或只是 length 在控制台中返回 0。

最佳答案

您正在使用 window.length .

Returns the number of frames (either <frame> or <iframe> elements) in the window.

var array = [21, 22];

console.log(length);
console.log(window.length);
console.log(array[length]);
<iframe></iframe>

关于javascript - 为什么 array[length] 返回列表的第一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39436026/

相关文章:

javascript - 如何根据范围过滤数组,然后在结果的两侧获取额外的样本

javascript - AngularJS 和 Webpack 集成

javascript - 我怎样才能摆脱只发生在一个特定按钮上的按钮悬停闪烁?

arrays - 用于对包含 32 个随机元素的列表进行排序的自适应排序算法与排序网络

ios - 如何快速查找自定义对象数组中某个键的所有对象的总和

Python:如何查找数组 x 中与数组 y 中的元素值接近的元素?

arrays - 计算相似的数组值

javascript - 通过单击 React Native 中的复选框来更改片段

javascript - 如果用户在我的响应式网站中以纵向模式单击切换按钮,则导航菜单会在横向模式下消失

Javascript:仅在函数中使用特定参数