当前位置:网站首页>ES6 -- Application of expansion operator
ES6 -- Application of expansion operator
2022-07-27 20:16:00 【Cheapskate syq】
<script>
var str = "abcdefg"
// Turn a string into an array
var arr = str.split("")
console.log(arr);
// ES6 Extension operators
var arr1 = [...str]
console.log(arr1);
let arr2 = [1, 2, 2, 3, 3, 4, 5]
let s = new Set(arr2) // It's an array of classes
// hold Set Class array to true array
let news = Array.from(s)
console.log(news);
// Extended operator implementation set Turns into a real array
let newss = [...s]
console.log(newss);
// You can't use the following methods , hold set Set to array
Array.prototype.slice.call(s)
// How to splice arrays
let aa1 = [1, 2, 3];
let aa2 = [4, 5, 6];
// concat-- Splicing
let newaa = aa1.concat(aa2)
console.log(newaa);
// Expand operator splicing
let newaa2 = [...aa1, ...aa2]
console.log(newaa2);
// Put the passed parameters , Make an array
// Traditional solutions
function fn() {
console.log(Array.prototype.slice.call(arguments));
}
fn(1, 2, 3, 4, 5)
// es6 How to solve
function fn(...a) {
// console.log([...arguments]);
console.log(a);
}
fn(1, 2, 3, 4, 5)
// The first parameter needs to use , Other composition array
function fn(z, ...a) {
// console.log([...arguments]);
console.log(z, a);
}
fn(1, 2, 3, 4, 5)
</script>边栏推荐
- 邬贺铨:因地制宜 数字化技术赋能“双碳”实践
- [C # network application programming] Experiment 3: process management exercise
- 最新获得淘宝app商品详情原数据 的API
- PyQt5快速开发与实战 4.3 QLabel and 4.4 文本框类控件
- 华为手机出货超苹果成全球第二,但面临大量库存需要清理
- shell
- Assignment 1 - Hello World ! - Simple thread Creation
- Redis-基本了解,五大基本数据类型
- Compiling ncnn with vs
- Libpcap library and pcap_ Sendpacket interface function understanding
猜你喜欢
随机推荐
ES6--解构赋值
Dcm11- write the function and configuration of the data service ($2e) according to the identifier [based on DaVinci configurator classic]
China business CDP white paper | love Analysis Report
2019年全球半导体市场收入4183亿美元,同比下滑11.9%
antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key
如何快速提升抖音小店三分钟回复率?哪些情况会影响抖音小店回复率呢?
C243: examination ranking
C# 后台GC 的前因后果
Qtexttospeech class of QT realizes voice broadcast function
libpcap库和pcap_sendpacket接口函数了解
使用cpolar建立一个商业网站(5)
Add joint control to gltf model
Technology sharing | how to do Assertion Verification in interface automated testing?
Built in function time date function
LED high precision scale scheme specification
产品经理:排查下线上哪里冒出个“系统异常”的错误提示
LED高精度体重秤方案规格书
Solve the problem of displaying the scroll bar when there is no data in the viewui table
解决 ViewUI 表格无数据时展示滚动条的问题
uva1377







