ES6 Note

SHOYUF

String

  1. unicode can use {} in most chinese character

  2. support iterate use fo of loop

for (let i of 'PHP is best language!') {
  console.log(i);
}
  1. String.repeat() (ES6)

repeat

  1. String.padStart() & String.padEnd() (ES8 Living Standard)

padStart
padEnd

Number

  1. Number.isFinite()
    test this number whether is finite

  2. Number.isNaN()
    test this number whether is not a Number

  3. a ** b
    Exponentiation

Math

  1. Math.trunc()
    return Integer

  2. Math.sign()
    judge a Number is postive or negative
    if(positive) return +1
    if(nagative) return -1
    if(zero) return 0
    if(NaN) return NaN

Function

  1. default value
function log(x, y = 'World') {
  console.log(x, y);
}

Array

  1. Array.find() & findIndex() (ES6)

find
findIndex

  1. Array.pop()
    Delete last element, return this element, modify origin Array.

  2. Array.push()
    Add a element behind last element in Array, return Array length, modify origin Array.

  3. Array.reverse()
    reverse Array, return new Array.

  4. Array.shift()
    Delete first element, return this element, modify origin Array.

  5. Array.sort()
    Sort by Unicode, return Array.

var items = [
  { name: 'Edward', value: 21 },
  { name: 'Sharpe', value: 37 },
  { name: 'And', value: 45 },
  { name: 'The', value: -12 },
  { name: 'Magnetic' },
  { name: 'Zeros', value: 37 }
];

items.sort(function (a, b) {
  if (a.value > b.value) {
    return 1;
  }
  if (a.value < b.value) {
    return -1;
  }
  // a 必须等于 b
  return 0;
});
  1. Array.splice(start, deleteCount, item1, item2, ...)
    From index start, delete some elements, after add some elements.
    return delete element Array or empty Array.

  2. Array.unshift()
    Add a element in the front of Array, return the new Array length.

本站使用署名 4.0 国际 (CC BY 4.0) 创作共享协议,转载请署名,图片请转存。

提醒:本文最后更新于 2542 天前,文中所描述的信息可能已发生改变,请谨慎使用。

湘ICP备13009407号