js类数组

<p></p>
//创建数组
const arr = []
const arr2 = new Array('10')
const arr3 = Array.from()
const arr4 = Array.of()
const arr5 = Array.prototype.slice()
// 类数组
1. 必须有长度 length
2. 从0开始的索引 0 1 2
3. 没有数组方法
// 哪里有类数组
1. 函数
function test(a,b){
console.log(arguments)
}
test(100,200)
------------
Arguments(2) [100, 200, callee: ƒ, Symbol(Symbol.iterator): ƒ]
0: 100
1: 200
callee: ƒ test(a,b)
length: 2
Symbol(Symbol.iterator): ƒ values()
[[Prototype]]: Object
------------
2. HTMLCollection
const p = document.getElementsByTagName('p')'
console.log('p')'
------------
HTMLCollection(24) [p.lh, p.lh, p.lh, p.lh, p.lh, p.lh, p.lh, p.lh, p.lh, p.lh, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.attr-text_3jLeU, p.c-color-text, p.c-color-text]
0: p.lh
1: p.lh
2: p.lh
3: p.lh
4: p.lh
5: p.lh
length: 5
[[Prototype]]: HTMLCollection
// 转为数组
array slice Array.from Array.apply 遍历复制
posted @ 2022-03-24 22:30  爱好跑步的小张  阅读(42)  评论(0)    收藏  举报