美文网首页
ES6 不断完善...

ES6 不断完善...

作者: 静候那一米阳光 | 来源:发表于2018-06-05 15:38 被阅读0次
  • 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'); //秒

相关文章

  • ES6 不断完善...

    ECMASCript 2015 (ES6) ECMASCript 2016 ECMASCript 2017 ECM...

  • javascript对象的属性遍历

    随着ES6的不断完善,javascript对对象的属性遍历的方式也逐渐增多。 下面我们来学习几种遍历的方式: fo...

  • 2018-09-27

    不断挑战 不断完善

  • 精进,不断完善

    给予,减去索取,等于人脉;付出,减去回报,等于胸怀。养成好的习惯受益终身、不断训练、持续积累。为什么分享的时候内容...

  • 不断完善自己

    你看从一年级,到五年级学生,经历了多少风风雨雨!我和妈妈一起加油,才到五年级,途中遇到,黄老师、张老师、赖老...

  • 不断完善自我

    随着年龄的增长,会越来越多的自我反省,会不自觉得去思过、纠错。 我们一生其实都在追寻内心的平衡,而...

  • 不断完善自己

    昨天忘记记一件事情,就是我受中医大夫嘱托,可以独立给患者做导平治疗了!开心? 继续努力! 今天白天没做什么有意义的...

  • 不断完善自我

    当你对一段关系感到厌倦,感到不快,不要从别人身上找原因,是自己的问题,简单说,修行不够,当你不断完善自我,哪有时间...

  • 不断完善自己

    这么多年,自己始终有一颗不断完善自己心。 始终觉得自己还不够好,想想让自己变得更加的优秀,更加的好。不管是常言行举...

  • ES6语法

    Tags: ES6 [TOC] ES6 常量 //ES6 const PI=3.1415926;//const声明...

网友评论

      本文标题:ES6 不断完善...

      本文链接:https://www.haomeiwen.com/subject/xktmsftx.html