前言
本系列主要整理前端面试中需要掌握的知识点。本节介绍ES6数组新增的扩展,包括扩展运算符、构造函数的新增方法、实例对象新增方法、数组的空位、排序稳定性。
文章目录
一、扩展运算符的应用
...用于将一个数组转为逗号分隔的参数序列。
console.log(...[1,2,3]);
console.log(...document.querySelectorAll('div'));

应用场景:
- 函数调用时,将一个数组变为参数序列
function push(array,...items){
array.push(...items)
console.log(array);
}
push([],1,2,3)
- 实现数组复制
const a = [1,2,3,4]
const b = [...a]
console.log(b);
- 实现数组合并
const arr1 = ['a','b','c'];
const arr2 = [1,2,3];
const arr3 = ['string']
console.log([...arr1,...arr2,...arr3]);
- 实现数组合并使用的是浅拷贝,如下例子:
const arr1 = ['a','b','c'];
const arr2 = [1,2,3,[1,2,3]];
const arr3 = ['string']
const arr4 =
最低0.47元/天 解锁文章
351

被折叠的 条评论
为什么被折叠?



