字符串的扩大

判断字符串是否蕴含在另一个字符中

let s = 'h'// 后果:trues.startsWith('hello')  // 是否在头部 // 后果:falses.endWith('hello')  // 是否在尾部  // 后果:trues.includes('hello')  // 字符串中是否存在 

字符串补全

let b = 'how'// 后果:aahowb.padStart('5','a')  // 有余5个字符,在头部补短少的'a' // 后果:howaab.padEnd('5','a') // 尾部补全 // 后果:"how  "b.padStart('5')  // 省略第二个参数用空格代替 

字符串反复

let a = 'hello'a.repeat(3)  // hellohellohello 反复三次'w'.repeat(3)  // www 反复三次'w'.repeat(3.5)  // 取整,反复三次

打消字符串空格

let s = ' abc 's.trim()  // 打消首尾空格s.trimStart()  // 打消首部空格s.trimEnd()  // 打消尾部空格

replaceAll()替换全副字符串

let s = 'hello's.replaceAll('l','o') // heooo

at字符串匹配输入

// 整数头部 复数尾部'hello'.at(2)  // l  从头部第0位开始,初始下标0'hello'.at(-1) // 0 从尾部第1位开始,初始下标1


数值的扩大

数值分隔符

容许给较长的数值增加分隔符,宰割不没有距离位数限度,不影响原值,不能在特殊符号前后。

let num = 1_00_000_000;

检测数值是否无限

无限:true

有限:false

Numbet.isFinite(10)  // trueNumbet.isFinite(NaN)  // false

检测是否为NaN

是:true

否:false

Number.isNaN(NaN) // trueNumber.isNaN(10)  // false

Number.parseInt()、Number.parseFloat()

将es5的全局办法parseInt()、parseFloat()改为Number.xxx,目标是缩小全局办法,使语言模块化。

parseInt('12.55');  // 12Number.parseInt('12.55');   // 12parseFloat('12.55');  // 12.55Number.parseFloat('12.55');   // 12.55

isInteger()判断是否为整数

留神:如果数值位数太长,可能会误判,IEEE754规范,53个二进制位后的数值会被抛弃

Number.isInteger(15)  // trueNumber.isInteger(1.5) // falseNumber.isInteger(false) // falseNumber.isInteger(3.0000000000000002) // true

Math.sign()判断是正、负、零,非数值会先转换数值

Math.sign('5') // 1 整数Math.sign(5) // 1Math.sign(-5) // -1 正数Math.sign(0)  // 0Math.sign(-0) // -0Math.sign(true) // 1Math.sign(false)  // -1// 其它 NaN

Math.hypot()办法返回所有参数的平方和和平方根

Math.hypot(3,4);  // 5

BigInt数据类型-大整数

大整数语法(后缀n):数据n

BigInt大整数能够放弃数值精度

let a = 2172141653n  // 大整数let b = 15346349309n  // 大整数console.log(a*b);  // 33334444555566667777n  // 能够放弃精度

一般数值与大整数不相等

15n === 15 // false

BigInt继承Object对象的两个实例办法

  • BigInt.prototype.toString()
  • BigInt.prototype.valueOf()

BigInt继承了Number对象的一个实例办法

  • BigInt.prototype.toLocaleString()

提供了三个静态方法

  • BigInt.asUintN(width, BigInt)
  • BigInt.asIntN(width, BigInt)
  • BigInt.parseInt(string[, radix])

BigInt转换规则

Boolean、Number、String三个办法。

转换后后缀n会隐没

Boolean(0n)  // falseNumber(2n) // 2String(2n)  // 2

数学运算和number类型基本一致,除法运算 / 会舍去小数局部,返回一个整数


函数的扩大

函数作用域

函数进行生命初始化时,参数局部会造成一个独自的作用域,等初始化完结,作用域隐没,该作用域在不设置参数默认值时不会呈现。

var x = 1// 传入参数 x = 2 , y = x , y = 2function f(x,y = x){     console.log(y);    }f(2)  // 2

rest参数(...残余运算符)

function fn(...val){  console.log(val)  // [1,2,3]}fn(1,2,3)

残余运算符只能放到最初一位

箭头函数

// 一行简写let b2 = num => num * 2// 等同于let b2 = (num) => {return num * 2}console.log(b2(10)); // 20

一行默认返回右侧的后果,大括号为代码块,如果箭头函数不是一行,则须要大括号包裹。

无返回值

let b2 = num => void num * 2console.log(b2(10)); // undefined

参数局部能够解构赋值。

简化回调函数

// 一般函数let fil = [1,2,3].filter(function(x){   return x == 2})console.log(fil); // [2]
// 箭头函数let fil2 = [1,2,3].filter(el=> el == 2 )console.log(fil2); // [2]

箭头函数this指向

箭头函数没有本人的this,而是援用外层的this。上面是 Babel 转箭头函数产生的 ES5 代码,就能分明地阐明this的指向。

// ES6function foo() {    setTimeout(() => {        console.log('id:', this.id);    }, 100);}// ES5function foo() {    var _this = this;        setTimeout(function () {        console.log('id:', _this.id);    }, 100);} 

箭头函数详解请看文章尾部链接


数组的扩大

Array.from() : 类数组转数组

Array.fo():数值转数组

find():返回符合条件的那一项

findIndex():返回符合条件的那一项的索引

findLast():从尾部查看,返回符合条件的那一项

filter() : 返回符合条件的数组成员数组

fill():以给定参数填充数组,第二个参数和第三个参数别离为填充的开始地位和完结地位的前一位,从0号位开始

entries():键值对遍历

keys():键名遍历

values():值遍历

includes():判断数组中是否存在对应的值,返回true和false

flat():拉平数组,默认拉平一层,参数为拉平几层,(Infinity深度拉平,不论多少层)

flatMap():拉平并用map函数迭代

at():参数为数组索引,整数从头(0开始),复数从尾(-1开始)

group():能够将数组分组,返回一个对象

let gr = [1,2,3,4,5]let g = gr.group(el=> el > 3 ? 'greater' : 'less')console.log(g);  // { greater: [4,5], less: [1,2,3] }

groupToMap():应用map对group迭代。

数组空位:数组空位指数组某一个地位没有任何值,undefined是有值的,如果没有值,那么数组空位会返回empty

Array(3);  // [empty x 3]也就是[,,,]

stor():排序

let arr = [2,3,6,4,5,1]// 升序console.log(arr.sort((a,b) => a - b));  // [1,2,3,4,5,6]// 降序console.log(arr.sort((a,b) => b - a));  // [6,5,4,3,2,1]
let arr2 = [{id:1,name:'名称1'},{id:3,name:'名称3'},{id:2,name:'名称2'},{id:6,name:'名称6'},{id:4,name:'名称4'},{id:5,name:'名称5'}]let so = arr2.sort((a,b)=>{ return a.id - b.id });console.log(so);// [{id: 1, name: '名称1'},{id: 2, name: '名称2'},{id: 3, name: '名称3'},{id: 4, name: '名称4'},{id: 5, name: '名称5'},{id: 6, name: '名称6'}]


箭头函数的具体解释:箭头函数详解

数组的扩大具体解读:数组的扩大和新增办法

对象的扩大具体解读:对象定义-解构-枚举属性遍历以及对象内函数

字符串办法具体解读 : 字符串办法