标签:site 一个 java website ber def es6 php class
const numbers = [‘one‘, ‘two‘, ‘three‘, ‘four‘]
es5:
const one = numbers[0]; //one const two = numbers[1]; //two
es6: 获取到相应位置的数组原素的值
const [one, two] = numbers;
console.log(one,two); //one two
//如果要获取数组0跟3 位置的元素的话,把那个位置留出来就行
const [one, , tow] = numbers;
//如果你想获取第一个元素的值和后面所有元素的值的话 (...others必须是在最后的一个位置)
const [one,...others] = numbers;
console.log(one,others); // one ["two","three","four"]
es6默认参数:
const details = [‘JellyBool‘, ‘wangrong.com‘, null]; const [name,website,category= ‘PhP‘] = details; console.log(name, website, category); // JellyBool wangrong.com null (只有category为undefined时,category值才为Php)
例子:交换 a 跟 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
标签:site 一个 java website ber def es6 php class
原文地址:https://www.cnblogs.com/wangRong-smile/p/11926453.html