当前位置:网站首页>Deconstruction function of ES6
Deconstruction function of ES6
2022-04-23 05:38:00 【Unspoken】
List of articles
Object to deconstruct - according to key Retrieval value
let demo = {
name: 'dao',
value: 0
}
// Basic usage
let {
name, value } = demo;
console.log(name);
console.log(value);
// Assignment usage
let {
name: localName } = demo;
console.log(localName);
// The default value is , stay demo I can't find it , The default value is 0
let {
type: localType = 0 } = demo;
// Nested deconstruction
let node = {
parent: {
child: {
name: 'dom',
value: 'class'
}
}
}
let {
parent: {
child } } = node;
console.log(child.name);
console.log(child.value);
An array of deconstruction - According to the location ( Indexes ) Retrieval value
let demo = ['red', 'green', 'blue'];
// Values and defaults
let [, second,,four = 'yellow'] = demo;
console.log(second);
console.log(four);
// Value exchange
let x = 1;
let y = 2;
[x, y] = [y, x];
console.log(x);
console.log(y);
// Nested arrays
let node = [[...demo], [1, 2, 3]];
let [[a], [b]] = node;
console.log(a);
console.log(b);
// Remaining items
let [first, ...rest] = demo;
console.log(first);
console.log(rest.length);
console.log(rest[0]);
Mixed deconstruction
// On the basis of the above , Structure the composite data structure of array and object
let node = {
parent: {
child: {
name: 'dom',
value: 'class'
}
},
type: [1, 2, 3]
}
let {
parent: {
chilid }, type: [first] } = node;
console.log(child.name);
console.log(first);
版权声明
本文为[Unspoken]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230536483030.html
边栏推荐
- Excel sets row and column colors according to cell contents
- Box collapse and margin collapse
- Transposed convolution
- mysql中duplicate key update
- acwing854. Floyd finds the shortest path
- IPI interrupt
- Step on the pit: Nacos uses startup CMD - M standalone startup error
- Introduction to data security -- detailed explanation of database audit system
- Traversal array, object parent-child communication props / $emit
- Quick app bottom navigation bar
猜你喜欢

Cross platform packaging of QT packaging program

Transposed convolution

C语言——恶搞关机小程序

OSI层常用协议

转置卷积(Transposed Convolution)

Branch and loop statements

Traversal array, object parent-child communication props / $emit

弘玑Cyclone RPA为国金证券提供技术支撑,超200个业务场景实现流程自动化

(11) Vscode code formatting configuration
![[triangle Yang Hui triangle printing odd even cycle JS for break cycle]](/img/9a/6cdc00e6056a1a47d2fbb8b9a8e975.png)
[triangle Yang Hui triangle printing odd even cycle JS for break cycle]
随机推荐
Edit, cancel, pull up menu
Various situations of data / component binding
Golang implements Ping connectivity detection case through exec module
what is wifi6?
MDN文档里面入参写法中括号‘[]‘的作用
[machine learning] scikit learn introduction
Xiuxian real world and game world
Cross platform packaging of QT packaging program
Quick app bottom navigation bar
Data bus realizes the communication between brother components
【华为机试】考试得分总数(如何处理答错的情况?回溯一次,代表答错一题)
Isosceles triangle - the 9th Lanqiao provincial competition - group C
Intel SGX preliminary learning and understanding notes (continuously updated)
[no title] Click the classification jump page to display the details
修仙真实世界与游戏世界
Frequently asked interview questions - 1 (non technical)
World and personal development
Pytorch deep learning practice_ 11 convolutional neural network
Shell instruction learning 1
合约锁仓漏洞