String
unicode can use
{}
in most chinese charactersupport iterate use fo of loop
for (let i of 'PHP is best language!') {
console.log(i);
}
String.repeat()
(ES6)
String.padStart()
&String.padEnd()
(ES8 Living Standard)
Number
Number.isFinite()
test this number whether is finiteNumber.isNaN()
test this number whether is not a Numbera ** b
Exponentiation
Math
Math.trunc()
return IntegerMath.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
- default value
function log(x, y = 'World') {
console.log(x, y);
}
Array
Array.find()
&findIndex()
(ES6)
Array.pop()
Delete last element, return this element, modify origin Array.Array.push()
Add a element behind last element in Array, return Array length, modify origin Array.Array.reverse()
reverse Array, return new Array.Array.shift()
Delete first element, return this element, modify origin Array.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;
});
Array.splice(start, deleteCount, item1, item2, ...)
From index start, delete some elements, after add some elements.
return delete element Array or empty Array.Array.unshift()
Add a element in the front of Array, return the new Array length.