ES6-8新特性
2017-12-04 本文已影响0人
木中木
let a = 2;
let b = 2**3;//ES7 幂运算
console.log(b);//b=8
console.log(b===Math.pow(2,3));
//数组包含运算
let c = [1,2,3,4,5];
console.log(c.includes(4))//包含运算直接算出bool值
//求对象属性key和value
let d = {a:1,b:2,c:3};
Object.keys(d).forEach((keys)=>{
console.log(keys)
})
Object.values(d).forEach((values)=>{
console.log(values)
})
//同时获取key和value
Object.entries(d).forEach(([keys,values])=>{
console.log(`${keys} is ${values}`)
})
//字符串填充位
let a = 'linjian'
console.log(a.padStart(10))
console.log(a.padEnd(15))
//合并对象
let b ={a:1,b:2,c:3};
let c = {a:2,b:3};
console.log(Object.defineProperties(b,Object.getOwnPropertyDescriptors(c)))
//下面是析构特殊点
let [x, y, ...z] = ['a'];
x // "a"
y // undefined
z // []