当前位置:网站首页>JS deconstruction assignment
JS deconstruction assignment
2022-06-30 04:09:00 【Runqing】
1. Deconstruction and assignment of arrays
// For unwanted values , Use ',', Skip the value .
const [first, , third, ...rest] = [1, 2, 3, 4, 5];
console.log(first) // 1
console.log(third) // 3
console.log(rest) // [4, 5]
const [a, b = 'default'] = []
console.log(a,b) // undefined 'default'
String、Set、Map All traversable objects can adopt deconstruction assignment :
// String
const [A,B,C,D] = 'abcd'
console.log(A,B,C,D) // a b c d
// Set
const[one, two, three, four] = new Set([1, 2, 3, 4])
console.log(one,two,three,four) // a b c d
2. Object's deconstruction assignment
let info = {
name:"David",
age: 24,
weight: 180
};
// 1. Also use '=' Give default values 2. The variable name can be given a new name by deconstruction
let {
name, age = 18, weight:height } = info;
console.log(name, age, height) // David 24 180
// 2. Take only some variables
let {
name: nickname, ...rest } = info;
console.log(nickname, rest) // David {age: 24, weight: 180}
// 3. More nesting levels , It can be correctly deconstructed only by corresponding to the order and level
let cellPhone = {
size: {
width: 375,
height: 667
},
package: ['type1', 'type2'],
price: 8888,
};
let {
size: {
width, height: weight }, package: [, t2 ], price } = cellPhone;
console.log(weight, t2) // 667 "type2"
Change the attribute value of the object by deconstructing the assignment
const obj = {
a: '123', b: '456'};
[obj.a, obj.b] = ['aaa', 'bbb'];
console.log(obj); // {a: "aaa", b: "bbb"}
stay for…of Use in
const obj = {
a: '123', b: '456'};
for (let [k, v] of Object.entries(obj)) {
console.log(k, v)
}
// a '123'
// b '456'
边栏推荐
- How to solve the problem of link hyperlinks when trying to link the database?
- .NET 7 的 JWT 配置太方便了!
- 解决navicat连接数据库遇到的问题
- Postman learning sharing
- 云原生入门+容器概念介绍
- DRF -- nested serializer (multi table joint query)
- Introduction to cloud native + container concept
- Jour 9 Gestion des scripts et des ressources
- 第十二天 进阶编程技术
- The school training needs to make a registration page. It needs to open the database and save the contents entered on the registration page into the database
猜你喜欢

Day 10 data saving and loading
![[note] Introduction to data analysis on June 7, 2022](/img/8b/9119bfdd10227f5c29ca2ece192880.png)
[note] Introduction to data analysis on June 7, 2022

(04). Net Maui actual MVVM

About manipulator on Intelligent Vision Group

el-upload上传文件(手动上传,自动上传,上传进度)

深入浅出掌握grpc通信框架

Jour 9 Gestion des scripts et des ressources
![[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII](/img/b2/0059659867e867a32b8e7cef567c8b.jpg)
[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII

The jupyter notebook kernel hangs up frequently and needs to be restarted

Wang Shuang - assembly language learning summary
随机推荐
base64.c
errno和perror
A solution to the problem of "couldn't open file /mnt/repodata/repomd.xml"
Errno and PERROR
DO280私有仓库持久存储与章节实验
Titanic(POJ2361)
DBT product initial experience
Linear interpolation of spectral response function
Ananagrams(UVA156)
dbt产品初体验
The new paradigm of AI landing is "hidden" in the next major upgrade of software infrastructure
Machine learning notes
[note] on May 28, 2022, data is obtained from the web page and written into the database
2021-11-04
Slam mapping, automatic navigation and obstacle avoidance based on ROS (bingda robot)
.NET 7 的 JWT 配置太方便了!
深入浅出掌握grpc通信框架
El upload Upload file (Manual upload, Automatic upload, upload progress)
[Thesis reading | deep reading] dane:deep attributed network embedding
lego_loam 代码阅读与总结