当前位置:网站首页>ES6 从入门到精通 # 07:解构赋值
ES6 从入门到精通 # 07:解构赋值
2022-07-28 03:13:00 【凯小默】
说明
ES6 从入门到精通系列(全23讲)学习笔记。
解构赋值
解构赋值是对赋值运算符的一种拓展,它针对数组和对象来进行操作。
优点:代码书写上简单易读
let man = {
name: "kaimo",
value: 313
}
// es5
let name = man.name;
let value = man.value;
// es6 完全解构
let {
name, value } = man;
console.log(name, value)

let obj = {
a: {
name: "kaimo"
},
b: [],
c: "hello cat"
}
// 不完全解构
let {
a } = obj;
console.log(a);
// 剩余运算符
let {
a, ...res } = obj;
console.log(a, res)
// 默认值
let {
a, b = 30 } = {
a: 20 };

对数组解构
let arr = [1, 2, 3];
let [a, b, c] = arr;
console.log(a, b, c);

// 可嵌套
let [a, [b], c] = [1, [2], 3];
console.log(a, b, c);

边栏推荐
猜你喜欢

Win11如何重命名音频设备

如何解决mysql深分页问题

Color recognition method and exploration based on MATLAB

Redis basic operation

STM32 RT-Thread虚拟文件系统挂载操作

Redis经典面试题总结

max_pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType

When QML uses layout layout, a large number of < unknown file >: QML qquicklayoutattached: binding loop detected for property circular binding warnings appear

Redis实现分布式锁

【SAML SSO解决方案】上海道宁为您带来SAML for ASP.NET/SAML for ASP.NET Core下载、试用、教程
随机推荐
Win11黑色桌面背景如何解决?
ssm整合(整合配置)
Summary of static blog building tools
Redis经典面试题总结
4天Excel实战训练营,0.01元特惠仅三天,赠200套学习资料包
过亿资产地址被拉入黑名单?Tether地址冻结功能该怎么用?
ThreadLocal使用场景
[uni app advanced practice] take you hand-in-hand to learn the development of a purely practical complex project 2/100
Win11输入法的选字框不见了怎么办?
ES6 从入门到精通 # 08:扩展的对象的功能
Redis communication protocol -- resp protocol
Shell writing specifications and variables
Color recognition method and exploration based on MATLAB
RBD块存储设备的扩容以及缩容操作(六)
静态博客搭建工具汇总
容器相关的概念
max_ pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType
并发编程面试题总结
LeetCode 第二十九天
C -- switch case statement