当前位置:网站首页>ES6 从入门到精通 # 12:数组的扩展方法一
ES6 从入门到精通 # 12:数组的扩展方法一
2022-08-09 22:39:00 【凯小默】
说明
ES6 从入门到精通系列(全23讲)学习笔记。
数组的方法
from
from() 将伪数组转换成真正的数组
例子:Arguments
function add() {
console.log(arguments)
// es5
console.log([].slice.call(arguments))
// es6
console.log(Array.from(arguments))
}
add(1,2,3,4)

例子:NodeList
let lis = document.querySelectorAll("li");
console.log(lis)
console.log(Array.from(lis))
// 扩展运算符
console.log([...lis])

from() 还可以接收第二个参数用来对每个元素进行处理
console.log(Array.from(lis, el => el.textContent))

of
of() 将任意的数据类型,转换成数组
console.log(Array.of(1,2,3,"666",{
a:777}))

copyWithin
copyWithin() 方法用于从数组的指定位置拷贝元素到数组的另一个指定位置中。

console.log(["Banana", "Orange", "Apple", "Mango", 1, 2, 3, 4].copyWithin(2,0));

find 跟 findIndex
find() 找出第一个符合条件的数组成员
findIndex() 找出第一个符合条件的数组成员的索引
console.log([1,2,3,4,-1,0,-9].find(n => n < 0))
console.log([1,2,3,4,-1,0,-9].findIndex(n => n < 0))

边栏推荐
猜你喜欢

Mysql集群 ShardingSphere

matplotlib散点图自定义坐标轴(文字坐标轴)

金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)

k8s部署mysql

深入理解多线程(第一篇)

金仓数据库 KingbaseGIS 使用手册(6.5. 几何对象编辑函数)

SRv6 performance measurement

什么是平面文件数据库? 如何导入多种格式的文件:DSV、JSON、XML?

MVC与MVVM模式的区别

Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first
随机推荐
ElasticSearcch集群
A Shanghai technology company was fined 220,000 for brushing orders, exposing the gray industry chain of online brushing
tiup cluster upgrade
恭喜获奖得主 | 互动有礼获赠 Navicat Premium
如何知道电脑开机记录?
多线程是同时执行多个线程的吗
直播预告 | ICML 2022 11位一作学者在线分享神经网络,图学习等前沿研究
关于服务治理
【接口测试】requests 库请求体字符串解码
Technology feast!Huayun Data brings six topics to OpenInfra Days China
函数习题(下)
国内十大活跃报表 BI 产品深度对比及点评
金仓数据库 KingbaseGIS 使用手册(6.6. 几何对象校验函数、6.7. 空间参考系函数)
了解什么是架构基本概念和架构本质
[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon
JS--popstate事件--使用/教程/实例
【集训DAY3】阶乘【数学】
新增一地公布2022下半年软考报考时间
【诗歌】枕上诗书
直播app开发搭建,flutter 实现自适应、自动换行、相对布局