Package Type
When accessing a base type value in read mode, an object of the corresponding base wrapper type is created, which facilitates data manipulation. Each wrapper type is mapped to a base type with the same name. Operation base type the newly created wrapper object is destroyed immediately after the statement is executed.
Actions performed in the background:
(1) Create an instance of a string type;
(2) Invoking the specified method on the instance
(3) Destroying this instance
var S1 = "some text"; var s2 = s1.substring (2); s1 = null;
First, Number type
(1): ValueOf () returns the value of the base type represented by the object
(2) toString ()
Parameter: Represents the cardinality, returns the string form of several binary values;
var num = 10;alert (num.tostring (2)); "1010"
(3) The ToFixed () method passes a parameter representing the decimal place, returning the string form of the numeric value represented by the specified decimal place;
Cases:
(4) The Toaexponential () method passes a parameter representing the exponent, returning the string form of the numeric value represented by the exponential notation;
(5) The Toprecision () method may return a fixed-size (fixed) format, or it may return an exponential (exponential) format
Ii. type of string
1. Methods for inheriting object objects
(1) valueOf (): Returns the original value of a string object.
(2) tolocalestring ():
(3) toString (): Returns a string.
Returns the base character type represented by the object
2. Character method
(1) CharAt () returns a string in single-character form
Cases:
var str = ' abc '; Str.charat (1); Return ' B '
(2) charCodeAt () returns the character encoding , with square brackets and a numeric index to access specific characters in the string;
Cases:
var stringvalue = "Hello World"; alert (Stringvalue.charcodeat (1)); "101"
3. String manipulation methods
(1) concat () and the plus operator ("+") stitching one or more strings, returning the stitched string;
Syntax: Stringobject.concat (stringx,stringx,..., stringx)
Example:
<script type= "Text/javascript" >var str1= "Hello" var str2= "world!" document.write (Str1.concat (str2)) </script>hello world!
4. Create a new string based on a substring
(1) Slice ()
Definition: Extracts a part of a string and returns the extracted part with a new string.
Syntax: Stringobject.slice (start,end)
var str= "Hello Happy world!" document.write (Str.slice (6))//happy world!
(2) substr ()
Definition: Extracts a specified number of characters from the starting index number in a string.
Syntax: Stringobject.substr (start,length)
var str= "Hello world!" document.write (Str.substr (3,7))//Lo Worl
(3) substring ()
Definition: A character used to extract a string intermediary between two specified subscripts.
Syntax: stringobject.substring (start,stop)
var str= "Hello world!" document.write (str.substring (3,7))//Lo W
5. String position method: Searches for the given substring from a string and returns the position in the substring (returns-1 if the substring is not found)
(1) indexOf () whether the specified substring is included in the query string. If present, returns the subscript of the substring in the string, otherwise returns-1.
var str = ' ABCDE '; Str.indexof (' B '); Return to 1str.indexof (' CD '); Returns 2str.indexof (' # # # '); Returns-1
(2) LastIndexOf () Searches forward the substring from the end of the string, the second parameter specifies a forward search from that position, ignoring all characters after that position
6. The trim () method creates a copy of the string, removing all the spaces of the predecessor and Suffix Trimleft (), TrimRight ()
var str = ' abc '; Str.trim ();//return ' abc ' str;//return ' ABC
7, String case conversion method: toLowerCase (), tolocal ()
var str = ' ABC1 '; Str.touppercase (); Returns ' ABC1 ' str; Back to ' ABC1 '
8. String pattern matching method: Match () receives only one parameter--regular expression or RegExp object, returns the first matching array; search () receives only one parameter--regular expression or RegExp object, returns the index of the first occurrence; replace () Can receive two parameters, the first parameter can make a RegExp object or a string, the second argument can be a string or a function;
9. Split () splits a string into an array of strings.
Grammar Stringobject.split (Separator,howmany)
var str= "How is you doing today?" document.write (Str.split ("") + "<br/>") document.write (Str.split ("") + "<br/>") document.write (str.split ("", 3)) How,are,you,doing,today? H,o,w,, A,r,e,, Y,o,u,, D,o,i,n,g,, T,o,d,a,y,? How,are,you
10. Localecompare () Method: Compares two strings in a local-specific order.
11. fromCharCode () method
Definition: Receive one or more character encodings and then convert them to a string
Syntax: String.fromCharCode (numx,numx,..., numx)
document.write (String.fromCharCode (72,69,76,76,79)) HELLO
Three, Boolean type
1, ValueOf (): Returns the base type value TRUE or False
2. ToString (): Returns the string "true" and "false"
monomer built-in objects
First, Global object:
1, definition: All the properties and functions defined in the global scope are properties of the global object;
2. Method:
(1) URI (common Resource table Identifier) encoding method:
(2) encodeURI (): Mainly used to encode the entire URI, not the special characters that belong to the URI are encoded;
(3) encodeURIComponent (): Mainly used to encode a paragraph in a URI, which encodes any non-standard characters it discovers;
(4) decodeURI () can only decode characters that are replaced with encodeURI ();
(5) decodeURIComponent () can only decode characters that are replaced with deodeuricomponent ()
(6) Eval () method: Only one parameter is received-the ECMAScript string to execute, and when the parser discovers that the eval () method is called in the code, it parses the passed-in parameter as the actual ECMAScript statement and then inserts the execution result into the original location. Code executed through eval () is considered part of the execution environment that contains the call, so the executed code has the same scope chain as the execution environment
Properties of the Global object: Special Values underfined, NaN, Infinity, and constructors for all native reference types such as Objec, Array, Function, Boolean, String, number, Date, REGEXP , Error
Second, the Math object
1. Properties of the Math object: MATH.E, Math.ln10, MATH.LN2, math.log2e, math.log10e, Math.PI, Math.sqrt1_2, Math.sqrt2
2. Methods of the Math object:
(1) Math.min () and Math.max () methods
(2) Rounding Method: Math.ceil () rounding up, Math.floor () rounding down, Math.Round () standard rounding
(3) The Math.random () method returns a random number greater than or equal to 0 less than 1, and the value = Math. Floor (Math.random () * Total number of possible values + first possible value)
JS review-Basic Package type (String, number), built-in object