(4)ES6解构赋值-字符串篇

字符串的解构赋值

let [a,b,c,d,e] = 'Apple';
console.log(a); //A
console.log(b); //p
console.log(c); //p
console.log(d); //l
console.log(e); //e

const { length:len } = 'Hello'; //这边不能用[]因为{}才有属性
console.log(len); //5

const { length } = "Hello World!";
console.log(length); //12

 

posted @ 2016-12-31 00:27  web全端小屋  阅读(256)  评论(0编辑  收藏  举报