当前位置:网站首页>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
边栏推荐
- Use of ES6 array
- (11) Vscode code formatting configuration
- uni使用的一些坑
- mysql中duplicate key update
- 使用宝塔+xdebug+vscode远程调试代码
- 50 SQL exercises, answers and detailed analysis
- 巴普洛夫与兴趣爱好
- Frequently asked interview questions - 3 (operating system)
- Excel 2016 cannot open the file for the first time. Sometimes it is blank and sometimes it is very slow. You have to open it for the second time
- SQL statement simple optimization
猜你喜欢

3d slicer中拉直体的生成

Flutter 新一代图形渲染器 Impeller

Cross platform packaging of QT packaging program

Frequently asked interview questions - 2 (computer network)

‘EddiesObservations‘ object has no attribute ‘filled‘

C language - Spoof shutdown applet

Breadth first search topics (BFS)

Fletter next generation graphics renderer impaller

QT displays the specified position and size of the picture

Necessity of selenium preloading cookies
随机推荐
Step on the pit: Nacos uses startup CMD - M standalone startup error
World and personal development
js数字大写方法
[machine learning] scikit learn introduction
Find the number of "blocks" in the matrix (BFS)
【华为机试】考试得分总数(如何处理答错的情况?回溯一次,代表答错一题)
deep learning object detection
Watch depth monitoring mode
selenium預先加載cookie的必要性
3d slicer中拉直体的生成
What financial products will benefit during May Day?
Three methods of list rendering
Quick app bottom navigation bar
Utf8 to STD: string and STD: string to utf8
巴普洛夫与兴趣爱好
Establish excel bookkeeping book through setting context menu
QSslSocket::connectToHostEncrypted: TLS initialization failed
refused connection
Golang implements Ping connectivity detection case through exec module
Jiugong magic square - the 8th Lanqiao provincial competition - group C (DFS and comparison of all magic square types)