首页 > 编程语言 > 详细

数组拓展

时间:2021-08-10 23:23:36      阅读:16      评论:0      收藏:0      [点我收藏+]

1.类方法

Array.from() 将类数组转数组

Array.of() 创建数组
// Array.from()
const divs = document.getElementsByTagName(‘div‘)
Array.from(divs).forEach(v => {
       console.log(v)
})

// Array.of()
const arry = Array.of(1,2,3)

2.实例方法

copyWithin(pos,start,end) // pos黏贴位置,  start复制的起始位置, end 复制的结束位置

find()  findIndex()

entries() keys()  values()

flat()  flatMap()

// 实现copyWithin()
Array.prototype.myCopyWithin = function(pos,start,end){
       return this.splice(pos,end-start+1,...this.slice(start-1,end)),this }
const arry = [0,1,2,3,4,5,6,7,8,9]
console.log(arry.copyWithin(3,4,8))
console.log(arry.myCopyWithin(3,4,8))

3.其它数组方法

splice(pos,count,a1,a2,a3)

数组拓展

原文:https://www.cnblogs.com/LunuZ/p/15125717.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!