当前位置:网站首页>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))

边栏推荐
猜你喜欢
随机推荐
全面解析FPGA基础知识
JSON对象和字符串相互转化
68. qt quick-qml multi-level folding drop-down navigation menu supports dynamic add/unload, support qml/widget loading, etc.
力扣:474.一和零
国内BI厂商一览
【AtomicInteger】常规用法
CAD 截断线段
The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
深入理解多线程(第一篇)
linux上使用docker安装redis
32 JZOF 】 【 print down on binary tree
新增一地公布2022下半年软考报考时间
多商户商城系统功能拆解25讲-平台端分销申请
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
多线程是同时执行多个线程的吗
一体化伺服电机在三轴钻孔机中的应用
2022/8/9 考试总结
ElasticSearcch集群
直播平台怎么搭建,原生js实现编辑器撤消/恢复功能
Technology feast!Huayun Data brings six topics to OpenInfra Days China









