当前位置:网站首页>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))
边栏推荐
- 金仓数据库 KingbaseGIS 使用手册(6.3. 几何对象创建函数)
- The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
- Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
- 什么是平面文件数据库? 如何导入多种格式的文件:DSV、JSON、XML?
- 【集训DAY4】矩形【线段树】
- tiup cluster start
- matplotlib散点图自定义坐标轴(文字坐标轴)
- 直播app开发搭建,flutter 实现自适应、自动换行、相对布局
- 68.qt quick-qml多级折叠下拉导航菜单 支持动态添加/卸载 支持qml/widget加载等
- 高手这样看现货白银走势图
猜你喜欢
随机推荐
集合运算样例
Explore the TiDB Lightning source code to solve the found bugs
Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first
harbor配置远程仓库
【JZOF】77 Print binary tree in zigzag
32 JZOF 】 【 print down on binary tree
如何知道电脑开机记录?
Mysql集群 ShardingSphere
MVC与MVVM模式的区别
How to know the computer boot record?
【mysql】查询今天9点
为什么刀具数据库无法打开?
直播间搭建,按钮左滑出现删除等操作按钮
Mysql/stonedb - slow SQL - 2022-08-09 Q16 analysis
金仓数据库 KingbaseGIS 使用手册(6.2. 管理函数)
k8s部署mysql
【JZOF】32从上往下打印二叉树
Technology feast!Huayun Data brings six topics to OpenInfra Days China
防火墙之系统防护
外包的水有多深?腾讯15k的外包测试岗能去吗?