Reference
Global
decodeURI()
Decodes a string escaped with encodeURI().
decodeURIComponent()
Decodes a string escaped with encodeURIComponent().
encodeURI
Encodes a URI by escaping certain characters.
encodeURIComponent
Encodes a URI component by escaping certain characters.
escape()
Encodes a string by replacing certain characters with escape sequences.
eval()
Evaluates a string of JavaScript code and returns the result.
isFinite()
Tests whether a value is a finite number.
isNaN()
Tests whether a value is the not-a-number value.
parseFloat()
Parses a number from a string.
parseInt()
Parses an integer from a string.
unescape()
Decodes a string encoded with escape().
Array
Array.concat()
Returns A new array
var a = [1,2,3];
a.concat(4, 5) // Returns [1,2,3,4,5]
Array.every()
test whether a predicate is true for every element
[1,2,3].every(function(x) { return x < 5; }) // => true: all elts are < 5
Array.filter()
return array elements that pass a predicate
[1,2,3].filter(function(x) { return x > 1; }); // => [2,3]
Array.forEach()
invoke a function for each array element
This method returns nothing.
var a = [1,2,3];
a.forEach(function(x,i,a) { a[i]++; }); // a is now [2,3,4]
Array.indexOf()
['a','b','c'].indexOf('b') // => 1
Array.lastIndexOf()
search backward through an array
Array.join()
concatenate array elements to form a string
a = new Array(1, 2, 3, "testing");
s = a.join("+"); // s is the string "1+2+3+testing"
Array.map()
compute new array elements from old
[1,2,3].map(function(x) { return x*x; }); // => [1,4,9]
Array.push()
append elements to an array
Array.pop()
remove and return the last element of an array
The new length of the array, after the specified values are appended to it.
var stack = []; // stack: []
stack.push(1, 2); //stack: [1,2] Returns 2
stack.pop(); // stack: [1] Returns 2
Array.reduce()
compute a value from the elements of an array
[1,2,3,4].reduce(function(x,y) { return x*y; }) // => 24: ((1*2)*3)*4
Array.reduceRight()
reduce an array from right-to-left
[2, 10, 60].reduceRight(function(x,y) { return x/y }) // => 3: (60/10)/2
Array.reverse()
reverse the elements of an array
a = new Array(1, 2, 3); // a[0] == 1, a[2] == 3;
a.reverse(); // Now a[0] == 3, a[2] == 1;
Array.shift()
shift array elements down,The former first element of the array.
var a = [1, [2,3], 4]
a.shift(); // Returns 1; a = [[2,3], 4]
Array.slice()
return a portion of an array
var a = [1,2,3,4,5];
a.slice(0,3);
a.slice(3);
a.slice(1,-1);
Array.some()
test whether a predicate is true for any element This method is very much like every()
Array.splice()
insert, remove, or replace array elements
var a = [1,2,3,4,5,6,7,8]
a.splice(1,2); // Returns [2,3]; a is [1,4]
a.splice(1,1); // Returns [4]; a is [1]
a.splice(1,0,2,3); // Returns []; a is [1 2 3]
Array.toLocaleString()
convert an array to a localized string
Array.toString()
This return value is the same string that would be returned by the join() method with no arguments. convert an array to a string
Array.unshift() insert elements at the beginning of an array
var a = [];
a.unshift(1); // a:[1]
a.unshift(22);// a:[22,1]
String
String.charAt()
get the ‘n’th character from a string
String.indexOf()
search a string
String.lastIndexOf()
search a string backward
String.match()
find one or more regular-expression matches
"1 plus 2 equals 3".match(/\d+/g) // Returns ["1", "2", "3"]
String.replace()
replace substring(s) matching a regular expression
String.search()
search for a regular expression
String.slice()
string.slice(start, end)
extract a substring
var s = "abcdefg";
s.slice(0,4)// Returns "abcd"
String.split()
break a string into an array of strings
String.substr()
string.substr(start, length)
extract a substring
String.substring()
string.substring(from, to)
return a substring of a string
String.toLowerCase()
convert a string to lowercase
String.toUpperCase()
convert a string to uppercase
Date
Function
.call
.apply
.bind
JSON
JSON.parse()
parse a JSON-formatted string
JSON.stringify()
serialize an object, array or primitive value
Math
Math.abs()
Computes an absolute value.
Math.ceil()
Rounds a number up.
Math.exp() Computes a power of e.
Math.floor() Rounds a number down.
Math.log() Computes a natural logarithm.
Math.max() Returns the larger of two numbers.
Math.min() Returns the smaller of two numbers.
Math.pow()
Computes x y
Math.random()
Computes a random number.
Math.round() Rounds to the nearest integer.
Number
Number.toExponential()
format a number using exponential notation
var n = 12345.6789;
n.toExponential(1);// Returns 1.2e+4
n.toExponential(5); // Returns 1.23457e+4
n.toExponential(10);
n.toExponential();
Number.toFixed()
format a number using fixed-point notation
var n = 12345.6789;
n.toFixed(); // Returns 12346: note rounding, no fractional part
n.toFixed(1); // Returns 12345.7: note rounding
n.toFixed(6);
(1.23e+20).toFixed(2);
(1.23e-10).toFixed(2) // Returns 0.00
Number.toPrecision()
format the significant digits of a number
var n = 12345.6789;
n.toPrecision(1); // Returns 1e+4
n.toPrecision(3); // Returns 1.23e+4
n.toPrecision(5);
n.toPrecision(10);
Object
Object.hasOwnProperty()
check whether a property is inherited
var o = new Object();
o.x = 3.14;
o.hasOwnProperty("x"); // Returns true: x is a local property of o