The essence of JavaScript language-methods
Method Array, Function, Number, Object, RegExp, StringArray
/* Array. concat (item ...) returns a new array without modifying the original array */var a = ['A', 'B', 'C']; var B = ['x', 'y ', 'Z']; var c =. concat (B, true); // c is ['A', 'B', 'C', 'x', 'y', 'z ', true]/* array. join (separator) constructs a string. The default separator "separator" is "," */var a = ['A', 'B', 'C'];. push ('D'); var c =. join (''); // c is 'abc';/* array. pop () removes the last element in array and returns this element */var a = ['A', 'B', 'C']; var c =. pop (); // a is ['A', 'B'] & c is 'C '/ * Array. push (item ...) return the length of the new array */var a = ['A', 'B', 'C'] when the item is near the end of an array. var B = ['x', 'y', 'z']; var c =. push (B, true); // a is ['A', 'B', 'C', ['x', 'y', 'z'], true] // c is 5;/* array. shift () removes the first element from the array and returns this element */var a = ['A', 'B', 'C']; var c =. shift (); // a is ['B', 'C'] & c is 'A'/* array. unshift (item ...) in contrast to the push method, the return value in ie6 is undefined */var a = ['A', 'B', 'C']; var r =. unshift ('? ',' @ '); // A is ['? ',' @ ', 'A',' B ', 'C'] // r is 5/* array. reverse () method reverses the order of elements in array. Returns the current array */var a = ['A', 'B', 'C']; var B =. reverse (); // both a and B are ['C', 'B', 'a']/* array. slice (start [, end]) Copies some arrays. start and end can all be negative */var a = ['A', 'B', 'C']; var B =. slice (0, 1); // B is ['a'] var c =. slice (1); // c is ['B', 'C'] var d =. slice (1, 2); // d is ['B']/* array. sort (comparefn) to be further studied */var n = [4, 8, 15, 16, 23, 42]; n. sort (); // n is [15, 16, 23, 4, 42, 8]/* array. splice (start, deleteCount, item ...) start from start in the array, remove deleteCount elements, and replace them with new items */var a = ['A', 'B', 'C']; var r =. splice (1, 1, 'ache', 'bug '); // a is ['A', 'ache', 'bug ', 'C'] // r is ['B']
Function
/* Function. apply (thisArg, argArray) apply method call function funarg, pass an object bound to this (thisArg) and an optional parameter array (argArray ). */
Number
/* Number. the toString (radix) method converts a number into a string. The optional parameter radix controls the base number between 2 and 36. The default value is 10 * // * number. the toExponential (fractionDigits) method converts a number into an exponential string * // * number. toFixed (fractionDigits) converts a number to a decimal string. fractionDigits indicates the number between 0 and 20 after the decimal point */
Object
/* Object. hasOwnProperty (name) checks whether the object contains the name attribute and returns true/false */
RegExp
/* Regexp.exe c (string) */var text =''+' This isBold <\/B>! <\/P> <\/body> <\/html> '; var tags =/[^ <>] + | <(\/?) ([A-Za-z] +) ([^ <>] *)>/g; var a, I; while (a = tags.exe c (text ))) {for (I = 0; I <. length; I + = 1) {document. writeln ('// [' + I + ']' + a [I]). entityify ();} document. writeln ();}/* regexp. the test (string) test method is the simplest/quickest method to use a regular expression. Returns true if regexp matches string, otherwise false */var B =/&. +;/. test ('Frank & beans '); // B is true
String
/* String. charAt (pos) */var name = 'curly '; var initial = name. charAt (0); // initial is 'C'/* string. charCodeAt (pos) */var name = 'curly '; var initial = name. charCodeAt (0); // initial is 67/* string. concat (string ...) */var s = 'C '. concat ('A', 'T'); // s is 'cat'/* string. indexOf (searchString, position) */var text = 'Mississippi '; var p = text. indexOf ('ss'); // p is 2 p = text. indexOf ('ss', 3); // p is 5 p = text. indexOf ('ss', 6); // p is-1/* string. lastIndexOf (searchString, position) */var text = 'Mississippi '; var p = text. lastIndexOf ('ss'); // p is 5 p = text. lastIndexOf ('ss', 3); // p is 2 p = text. lastIndexOf ('ss', 6); // p is 5/* string. localeCompare (that) */var m = ['aaa', 'A', 'aaa', 'A', 'aaa']; m. sort (function (a, B) {return. localeCompare (B) ;}); // m (in some locale) is ['A', 'A', 'aaa ', 'aaa']/* string. match (regexp) * // * string. replace (searchValue, replaceValue)Only replace the previous matching Value*/Var result = "mother_in_law ". replace ('_', '-');/* string. search (regexp) */var text = 'and in it he says "Any damn fool cold'; var pos = text. search (/["']/); // pos is 18/* string. slice (start, end) is the same as string. substring (start, end) * // * string. split (separator, limit) */var digits = '000000'; var a = digits. split ('', 5); // a is ['0', '1', '2', '3', '123'] var text = 'Last, first, middle '; var d = text. split (/\ s *, \ s */); // d is ['last', 'First ', 'middle']/* string. substring (start, end) * // * string. toLocaleLowerCase () * // * string. toLocaleUpperCase () * // * string. toLowerCase () * // * string. toUpperCase () * // * String. fromCharCode (char ...) */var a = String. fromCharCode (67, 97,116); // a is 'cat'