当前位置:网站首页>ES6之解构函数
ES6之解构函数
2022-04-23 05:37:00 【不知言】
对象解构-根据key检索取值
let demo = {
name: 'dao',
value: 0
}
// 基础用法
let {
name, value } = demo;
console.log(name);
console.log(value);
// 赋值用法
let {
name: localName } = demo;
console.log(localName);
// 默认值,在demo中找不到时,默认赋值为0
let {
type: localType = 0 } = demo;
// 嵌套解构
let node = {
parent: {
child: {
name: 'dom',
value: 'class'
}
}
}
let {
parent: {
child } } = node;
console.log(child.name);
console.log(child.value);
数组解构-根据位置(索引)检索取值
let demo = ['red', 'green', 'blue'];
// 取值和默认值
let [, second,,four = 'yellow'] = demo;
console.log(second);
console.log(four);
// 值交换
let x = 1;
let y = 2;
[x, y] = [y, x];
console.log(x);
console.log(y);
// 嵌套数组
let node = [[...demo], [1, 2, 3]];
let [[a], [b]] = node;
console.log(a);
console.log(b);
// 剩余项
let [first, ...rest] = demo;
console.log(first);
console.log(rest.length);
console.log(rest[0]);
混合解构
// 在以上的基础上,对数组与对象的复合数据结构进行结构
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);
版权声明
本文为[不知言]所创,转载请带上原文链接,感谢
https://blog.csdn.net/WangYanWenXin/article/details/124344868
边栏推荐
- [untitled] Notepad content writing area
- 合约锁仓漏洞
- Similarities and differences between vector and array (notes)
- acwing854. Floyd finds the shortest path
- Basic knowledge of redis
- Multiple mainstream SQL queries only take the latest one of the data
- Frequently asked interview questions - 1 (non technical)
- solidity合约DOS攻击
- ‘EddiesObservations‘ object has no attribute ‘filled‘
- Range of numbers (dichotomous classic template topic)
猜你喜欢

QT displays the specified position and size of the picture

STL learning notes 0x0001 (container classification)

转置卷积(Transposed Convolution)

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

Pol / select / EPO

Breadth first search topics (BFS)

3d slicer中拉直体的生成

Double click The jar package cannot run the solution

Fast application fuzzy search

Establish excel bookkeeping book through setting context menu
随机推荐
Hongji | how does HR carry out self change and organizational change in the digital era?
Call the interface to get the time
Camera imaging + homography transformation + camera calibration + stereo correction
qt. qpa. plugin: Could not find the Qt platform plugin “xcb“ in ““
xxl-job采坑指南xxl-rpc remoting error(connect timed out)
字符识别easyocr
Double click The jar package cannot run the solution
Quick app bottom navigation bar
solidity合约DOS攻击
合约锁仓漏洞
Create process memory management copy_ Mm - processes and threads (IX)
橙单微服务之批量导入
可执行程序执行流程
Escape characters \ splicing of data formats
Data bus realizes the communication between brother components
Cross platform packaging of QT packaging program
Xiuxian real world and game world
Fast application fuzzy search
踩坑:nacos利用startup.cmd -m standalone启动错误
Traversal array, object parent-child communication props / $emit