当前位置:网站首页>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>边栏推荐
- Unity2d dynamic cartoon script (animation demonstration II for the chapter of Tiger Bridge)
- Built in function time date function
- 华为全联接大会2022开启曼谷之旅;Facebook推视频收入分成功能,创作者可获20%分成…
- ZJNU 22-07-26 competition experience
- C # network application programming, experiment 2: IP address translation and domain name resolution exercises
- 图解LeetCode——剑指 Offer II 115. 重建序列(难度:中等)
- 速卖通:按关键字搜索商品 API
- 学习Blender必备的12款动画插件,来了解一下
- Codeforces Round #810 (Div. 2)B.party(思维题)超详细题解
- [IOT] Wei Peng: Interpretation of 6000 + words | seven necessary product management tools for product people in 2022 (version 1.0)
猜你喜欢

PMP practice once a day | don't get lost in the exam -7.27 (including agility + multiple choices)

Add joint control to gltf model

How to encrypt the data in MySQL database? Mysql8.0 comes with new features

Datepicker date selector in viewui compatible solution in ie11 browser

Chapter 3 basic operation

New library online | cnopendata detailed address data of all patents in China

PyQt5快速开发与实战 4.7 QSpinBox(计数器) and 4.8 QSlider(滑动条)

Ten year test old bird talk about mobile terminal compatibility test

Can software testing be learned in 2022? Don't learn, software testing positions are saturated

PC Museum (3) MITs Altair 8800
随机推荐
Detailed introduction to common coordinate system of cesium
由单片机XTALIN引脚和XTALOUT引脚导出的对晶体震荡电路的深入理解
PKI/TLS 工具之CFSSL —— 筑梦之路
In 2019, the global semiconductor revenue fell by 12% year-on-year, and China's market share ranked first
Assignment 1 - Hello World ! - Simple thread Creation
Ms721 load test
PyQt5快速开发与实战 4.5 按钮类控件 and 4.6 QComboBox(下拉列表框)
Technology sharing | how to do Assertion Verification in interface automated testing?
[redis] several deployment methods of redis
长安链数据存储源码分析
什么是多层感知机(什么是多层感知机)
想转行软件测试,先过这三关,包含一份3000字超全测试学习指南
Dcm11- write the function and configuration of the data service ($2e) according to the identifier [based on DaVinci configurator classic]
JS 数组方法 forEach 和 map 比较
Use cpolar to build a business website (5)
图解LeetCode——剑指 Offer II 115. 重建序列(难度:中等)
最新获得淘宝app商品详情原数据 的API
LED high precision scale scheme specification
十年测试老鸟聊聊移动端兼容性测试
uva1421