gpt4 book ai didi

javascript - `["length"]` 是如何工作的?

转载 作者:行者123 更新时间:2023-12-03 06:06:47 24 4
gpt4 key购买 nike

今天读undersocre时,发现一个有趣的语法["length"]

例如:

"hello"["length"] //5
[1,2,3,4]["length"] //4

这适用于 Chrome、Firefox 甚至 IE5!

这是一个原生的js方法还是以[1,2,3][“1”]之类的数组方式运行?

最佳答案

这是 Array 的标准属性: Array#length

The length property represents an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.

或者 String 的标准属性: String#length

The length property represents the length of a string.

这是 property accessor 的不同用法.

[0, 1, 2].length
[0, 1, 2]['length']

关于javascript - `["length"]` 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39506945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com