- ECMASCript 2015 (ES6)
- ECMASCript 2016
- ECMASCript 2017
ECMAScript 2016
Array.prototype.includes
查找某个项是否在Array中(包括NaN)
const arr = [ 1, 'a', true, null, undefined, {}, NaN, Math];
arr.includes(1);//true
arr.includes('a');//true
arr.includes(true);//true
arr.includes(false);//false
arr.includes(null);//true
arr.includes(undefined);//true
arr.includes({});//false
arr.includes(NaN);//true
arr.includes(Math);//true
const arr = [];
arr.includes(1);//false
arr.includes('a');//false
arr.includes(true);//false
arr.includes(false);//false
arr.includes(null);//false
arr.includes(undefined);//false
arr.includes({});//false
arr.includes(NaN);//false
arr.includes(Math);//false
指数运算符
**
7**2 // 49
ECMAScript 2017
Object.keys() Object.entries()
- Object.keys()返回Object自身属性的所有值。(排除原型链中的值)
- Object.entries()以数组方式返回keys和values。(排除原型链中的值)
Object.keys([1, 2, 3]) //["0","1","2"]
Object.entries([1, 2, 3]) //[["0",1],["1",2],["2",3]];
new Map(Object.entries([1, 2, 3])) // {"0" => 1, "1" => 2, "2" => 3}
String padding
'someString'.padStart(numberOfCharcters [,stringForPadding]);
'5'.padStart(10) // ' 5'
'5'.padStart(10, '=*') //'=*=*=*=*=5'
'5'.padEnd(10) // '5 '
'5'.padEnd(10, '=*') //'5=*=*=*=*='
【栗子】
let date = new Date();
date.getFullYear().toString().padStart(4,'0');//年
now.getMonth()+1).toString().padStart(2,'0');//月
date.getDate().toString().padStart(2,'0'); //日
date.getHours().toString().padStart(2,'0'); //时
date.getMinutes().toString().padStart(2,'0'); //分
date.getSeconds().toString().padStart(2,'0'); //秒
网友评论