当前位置:网站首页>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.2. 管理函数)
tiup cluster upgrade
上海一科技公司刷单被罚22万,揭露网络刷单灰色产业链
测试2年,当时身边一起入行的朋友已经月薪20k了,自己还没过万,到底差在了哪里?
[Interface Test] Decoding the request body string of the requests library
Sqlserver restricts the ip under which accounts can access the database
【诗歌】枕上诗书
金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
68. qt quick-qml multi-level folding drop-down navigation menu supports dynamic add/unload, support qml/widget loading, etc.
联盟链技术应用的难点
后台管理实现导入导出
多线程是同时执行多个线程的吗
SRv6性能测量
Has your phone ever been monitored?
【SSL集训DAY2】Sequence【数学】
Snap: 322. Change of Change
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
2021年国内外五大BI厂商——优秀的商业智能工具推荐
k8s部署mysql
tiup cluster template