X. array of deconstruction

const numbers = ['one', 'two', 'three', 'four']

  

es5:

const one = numbers[0];    //one     
const two = numbers[1];    //two

  

es6: Get value corresponding to the position of the original array of pixel

const [One, TWO] = a Numbers; 

console.log (One, TWO); // One TWO

// If you want to get the elements of the array 0 3 position with words, to stay out of that position on the line
const [one,, tow] = a Numbers;

// If you want to get back the value of all the elements and the first element of the case (... others must be in the final position)
const [one, ... Others] = a Numbers;
console.log ( one, others); // one [ "two", "three", "four"]

  

es6 default parameters:

Details = const [ 'JellyBool', 'wangrong.com', null]; 

const [name, Website, category = 'PhP'] = Details; 

the console.log (name, Website, category); // null JellyBool wangrong.com (only category is undefined, category value only as Php)

  

Examples: switching with a value of b

let a = 10;
let b = 20;

 

es5:

let temp;
temp = a;
a = b;
b = temp;
console.log(a,b);    //20 10

  

es6:

[a,b] = [b,a];

console.log(a,b);    //20 10

  

Guess you like

Origin www.cnblogs.com/wangRong-smile/p/11926453.html