JS ES6 destructuring assignment

Destructuring assignment

ES6 allows extracting values ​​from arrays and objects and assigning values ​​to variables according to certain patterns, which is called destructuring.

Destructuring and Assignment of Array

let [a, b] = [1, 2] // a = 1, b = 2
let [a, b, c = 100] = [1, 2]

Object destructuring assignment

let {
    
    hello, world} = {
    
    hello: 1, world: 2}
let {
    
    hello = 1, world} = {
    
    world: 2}
let {
    
    hello:w, world} = {
    
    world: 2}

String structure assignment

Destructuring assignment of function parameters

Guess you like

Origin blog.csdn.net/weixin_43176019/article/details/109216256