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

边栏推荐
猜你喜欢

Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research

如何正则匹配乱码?

【集训DAY5】快速排序【模拟】【数学】

《GB5084-2021》PDF下载

Travel with Shengteng: See all the AI attractions in Jinling City in one day
![[Interface Test] Decoding the request body string of the requests library](/img/99/82ef792dacd398a8a62dd94f235a91.png)
[Interface Test] Decoding the request body string of the requests library

中国SaaS企业排名,龙头企业Top10梳理

高手这样看现货白银走势图

首席信息官如何将可持续性和技术结合起来

【集训DAY4】异或【字典树】
随机推荐
How to know the computer boot record?
伦敦银行情中短线的支撑和阻力位
2020年度SaaS TOP100企业名单
金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
CAD 绘制圆角处理
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
Forbidden (CSRF token missing or incorrect.): /
Explore the TiDB Lightning source code to solve the found bugs
巴比特 | 元宇宙每日必读:国内首个数字人产业专项支持政策发布,2025年北京数字人产业规模将破500亿元...
33. Fabric通道、组织、节点、权限间关系
如何正则匹配乱码?
基于 RocksDB 实现高可靠、低时延的 MQTT 数据持久化
金仓数据库 KingbaseGIS 使用手册(6.3. 几何对象创建函数)
&& 不是此版本的有效语句分隔符
带着昇腾去旅行:一日看尽金陵城里的AI胜景
力扣:322. 零钱兑换
首席信息官如何将可持续性和技术结合起来
为什么刀具数据库无法打开?
complete knapsack theory