当前位置:网站首页>ES6--拓展运算符运用
ES6--拓展运算符运用
2022-07-27 17:48:00 【小气鬼SYQ】
<script>
var str = "abcdefg"
// 把字符串转为数组
var arr = str.split("")
console.log(arr);
// ES6拓展运算符
var arr1 = [...str]
console.log(arr1);
let arr2 = [1, 2, 2, 3, 3, 4, 5]
let s = new Set(arr2) //他是个类数组
// 把Set类数组转为真数组
let news = Array.from(s)
console.log(news);
// 拓展运算符实现set转为真正的数组
let newss = [...s]
console.log(newss);
// 不可以用下面的方法,把set集合转为数组
Array.prototype.slice.call(s)
// 拼接数组的方法
let aa1 = [1, 2, 3];
let aa2 = [4, 5, 6];
// concat--拼接
let newaa = aa1.concat(aa2)
console.log(newaa);
// 拓展运算符拼接
let newaa2 = [...aa1, ...aa2]
console.log(newaa2);
// 把传过来的多个参数,组成数组
// 传统解决方式
function fn() {
console.log(Array.prototype.slice.call(arguments));
}
fn(1, 2, 3, 4, 5)
// es6方式解决
function fn(...a) {
// console.log([...arguments]);
console.log(a);
}
fn(1, 2, 3, 4, 5)
// 第一个参数需要使用,其他组成数组
function fn(z, ...a) {
// console.log([...arguments]);
console.log(z, a);
}
fn(1, 2, 3, 4, 5)
</script>边栏推荐
- 西数移动硬盘无法读取(高枕无忧的成语)
- MVCC的底层原理
- 汇顶科技:收购恩智浦VAS业务已完成交割
- How to run kevinchappell / FormBuilder
- Normalization and standardization
- 电容串联与并联以及电容串联与平衡电阻
- Assignment 1 - Hello World ! - Simple thread Creation
- JS 数组方法 forEach 和 map 比较
- Understanding of basic concepts of channel capacity and channel bandwidth
- Program design Comprehensive Experiment III
猜你喜欢

2022 love analysis · smart community manufacturer panoramic report manufacturer solicitation

Ms721 load test

电容串联与并联以及电容串联与平衡电阻

Understanding of basic concepts of channel capacity and channel bandwidth

技术分享 | 接口自动化测试中,如何做断言验证?

信道容量、信道带宽基本概念的理解

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

PC Museum (3) MITs Altair 8800

长安链数据存储源码分析

Product Manager: check where there is an error prompt of "system exception" on the offline
随机推荐
ACL11.12
邬贺铨:因地制宜 数字化技术赋能“双碳”实践
康佳半导体首款存储主控芯片量产出货,首批10万颗
Connection pool - return connection details (Part 1)
Built in function time date function
NAT 11.16
【PyTorch系列】PyTorch之torchvision 图像处理库详解
Normalization and standardization
2019年中国智能机市场:华为拿下近4成份额,稳坐国内第一
Cfssl of pki/tls tool -- the road to dream
Leetcode exercise 2 - sum of two numbers
Kubectl's access to pod logs -- the way to build a dream
C170: retest screening
What does bus mean
PC Museum (3) MITs Altair 8800
PMP practice once a day | don't get lost in the exam -7.27 (including agility + multiple choices)
LED高精度体重秤方案规格书
JS array method foreach and map comparison
Built in functions other functions
华为150人团队驰援,武汉“小汤山”5G基站火速开通!