今天读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/