当前位置:网站首页>ES6--解构赋值
ES6--解构赋值
2022-07-27 17:48:00 【小气鬼SYQ】
<script>
// 传统数组赋值
let arr = ["前端", "后端", "大数据"]
let q = arr[0]
let h = arr[1]
let d = arr[2]
console.log(q, h, d);
// es6解构赋值--数组解构赋值
let [a, b, c] = arr
console.log(a, b, c);
// 传统对象赋值
let obj = { name: "张三", age: 20 }
let name1 = obj.name;
let age1 = obj.age
console.log(name1, age1);
// es6解构赋值--对象解构赋值
let { name2, age2 } = obj
console.log(name2, age2);
// 赋值和顺序无关,属性名和变量名必须一致
// let { name, age, data: { msg, status } } = { name: "张三", age: 20, data: { msg: "ok", status: 200 } }
// console.log(name, age, msg, status);
// 给解构出来的变量修改名字
// let { name: uname, age: uage, data: { msg: umsg, status: ustatus } } = { name: "张三", age: 20, data: { msg: "ok", status: 200 } }
// console.log(uname, uage, umsg, ustatus);
// 给解构出来的变量添加默认值
// 当对象里的属性值是undefined,或者没有这个属性,这时候就给变量赋值成默认值
let { name: uname = "李四", age3 = 50, data: { msg: umsg, status: ustatus } } = { name: undefined, age3: undefined, data: { msg: "ok", status: 200 } }
console.log(uname, age3, umsg, ustatus);
</script>边栏推荐
- Product Manager: check where there is an error prompt of "system exception" on the offline
- Common errors reported by pytorch
- 内置函数时间日期函数
- 预处理与宏定义
- An in-depth understanding of crystal oscillation circuit derived from xtalin pin and xtalout pin of single chip microcomputer
- C # network application programming, experiment 1: WPF exercise
- Kubectl's access to pod logs -- the way to build a dream
- Unity2d dynamic cartoon script (animation demonstration II for the chapter of Tiger Bridge)
- C171: attendance system
- Normalization and standardization
猜你喜欢

第2章 入门

连接池-归还连接详解(上)

Chapter 3 basic operation

2022年,软件测试还能学吗?别学了,软件测试岗位饱和了...

Product Manager: check where there is an error prompt of "system exception" on the offline

antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key

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

2022 love analysis · smart community manufacturer panoramic report manufacturer solicitation

Source code analysis of Chang'an chain data storage

Rodin installs the SMT solvers plug-in
随机推荐
什么是多层感知机(什么是多层感知机)
华为手机出货超苹果成全球第二,但面临大量库存需要清理
如何快速提升抖音小店三分钟回复率?哪些情况会影响抖音小店回复率呢?
C171: attendance system
Wu Hequan: digital technology empowering "double carbon" practice according to local conditions
LeetCode练习2——两数之和
New library online | cnopendata detailed address data of all patents in China
Compiling ncnn with vs
邬贺铨:因地制宜 数字化技术赋能“双碳”实践
办公自动化解决方案——DocuWare Cloud 将应用程序和流程迁移到云端的完整的解决方案
Clickhouse 实现 MaterializedPostgreSQL
2019年中国智能机市场:华为拿下近4成份额,稳坐国内第一
会员卡头部组件使用文档
第3章 基本操作
由单片机XTALIN引脚和XTALOUT引脚导出的对晶体震荡电路的深入理解
内置函数其它函数
2022 love analysis · smart community manufacturer panoramic report manufacturer solicitation
传英特尔将停掉台积电16nm代工的Nervana芯片
Online judge output overrun
【PyTorch系列】PyTorch之torchvision 图像处理库详解