(1) Number Creation method:varmynum=NewNumber (value);varmynum=number (value), commonly used properties and methods: ToString (): Converts the numbers to strings, using the specified cardinality. ValueOf (): Returns the base numeric value of a number object. Number Codevarnum =NewNumber (5); alert (typeofNUM);//ObjectAlert (typeofNum.tostring ());//stringAlert (typeofNum.valueof ());// Number (2) Boolean creation methodvarb =NewBoolean (value);//constructor Functionvarb = Boolean (value);//Conversion FunctionsCommon Properties and methods: ToString (): Converts the logical value to a string and returns the result. ValueOf (): Returns the original value of the Boolean object. Boolean Codevarb =NewBoolean (5); alert (typeofb);//ObjectAlert (typeofB.tostring ());//stringAlert (typeofB.valueof ());//Boolean (3) string Creation methodvarstr =NewString (s);varstr =String (s); Common properties and methods: CharAt (): Returns the character at the specified position. charCodeAt (): Returns the Unicode encoding of the character at the specified position. Split () splits the string into an array of strings. SUBSTR () extracts the specified number of characters from the starting index number in the string. SUBSTRING () extracts the characters between two specified index numbers in a string. IndexOf () retrieves a string. LastIndexOf () searches the string from the back forward. toLowerCase () Converts the string to lowercase. toUpperCase () Converts the string to uppercase. Boolean Codevarstr =NewString ("A-b-cdcjk-h"); alert (str.length);//Tenalert (Str.charat (4));//Calert (Str.charcodeat (4));// Aboutalert (Str.indexof ("C"));//4alert (Str.lastindexof ("C"));//6vararr = Str.split ("-"); for(vari=0;i<arr.length;i++) {alert (arr[i]);} Alert (STR.SUBSTR (2, 3));//b-calert (str.substring (2, 3));//balert (Str.touppercase ()); (4The Arrayarray object is used to store multiple values in a single variable. How to createvararr =NewArray ();//create an empty arrayvararr =NewArray (size);//creates an array of a specified lengthvararr =NewArray (element0, Element1, ..., ELEMENTN);//when an array is created, the direct instantiation of the member elementvararr = []//Empty Arrayvararr = [1, 5,45,78,d]//when an array is created, the direct instantiation of the member elementCommon Properties and methods length sets or returns the number of elements in the array. Join () Places all elements of an array into a string. element is delimited by the specified delimiter. Pop () deletes and returns the last element of the array reverse () reverses the order of the elements in the array. Sort () Sorts the elements of an array into an arrays codevararr = [3, "Z", 1, "Java", ' JS ',true, 4];alert (arr.length);//7alert (Arr.join ("-"));//3-7-1-java-js-true-4alert (Arr.pop ());//4alert (arr);//3,7,1, "Java", ' JS ', Truealert (Arr.push ("R"));//8alert (arr);//3,7,1, "Java", ' JS ', True,ralert (Arr.reverse ());//reverse Orderalert (Arr.sort ());//Sort by string dictionary order (5the Datedate object is used to process the date and time. How to createvarMydate=NewDate ()varMydate=NewDate (millisecond value);//represents a millisecond value starting from 1970-1-1 to the present;Common Properties and Methods getFullYear () returns the year from a Date object with a four-digit number. Date () Returns the day and time. GetDate () returns a day in one months from the Date object (1 ~ 31). GetDay () Returns a day of the week from the Date object (0 ~ 6). GetMonth () returns the month from the Date object (0 ~ 11). GetHours () returns the hour of the Date object (0 ~ 23). Getminutes () returns the minute of the Date object (0 ~ 59). Getseconds () returns the number of seconds of the date object (0 ~ 59). Getmilliseconds () returns the milliseconds of the Date object (0 ~ 999). GetTime () returnsJanuary 1970 on 1the number of milliseconds since the day. toLocaleString () Converts a Date object to a string based on the local time format. Date CodevarDate =NewDate (); alert (date.tostring ()); alert (date.tolocalestring ()); Alert ("Year:" +date.getfullyear ());// .Alert ("Month:" +date.getmonth ());//3Alert ("Date:" +date.getdate ());// atAlert ("Day:" +date.getday ());//3varTime1 =date.gettime ();varTime2 = 1*24*60*60*1000alert (time1) alert (NewDate (time1+time2). toLocaleString ()); (6the math creation method is not a class of objects like Date and String, so there is no constructor for math (), a function like Math.sin () is just a function, not a method of an object. You do not have to create it, and you can invoke all of its properties and methods by using Math as an object. Common Properties and methods: Pi returns PI (approximately equal to 3).14159). ABS (x) The absolute value of the return number. The POW (x, y) returns the y power of X. Ceil (x) is rounded on the logarithm. Floor (x) is rounded down with a logarithmic. Max (x, y) returns the highest value in X and Y. Min (x, y) returns the lowest value in X and Y. Random () returns0 ~ 1the random number between. Round (x) rounds the number to the nearest integer. Math Codevarx = "897"; alert (Math.Abs (x));//897varx = 12.34;vary = 2;varz = 4; alert (Math.ceil (x));// -Alert (Math.floor (x));// AAlert (Math.Round (x));// Aalert (Math.pow (Y, z));// -alert (Math.random ()); (7) RegExp Creation MethodvarReg =NewRegExp (pattern, attributes);varReg =/*Regular rule $/; rules and notation: [0-9] Find any number from 0 to 9. [A-z] finds any characters from lowercase a to lower Z. [A-z] finds any characters from uppercase A to uppercase Z. [A-z] finds any characters from uppercase A to lowercase z. [ADGK] finds any character within a given collection. [^ADGK] finds any character outside the given set. (Red|blue|green) to find any of the specified options: Finds a single character, in addition to line breaks and line terminators. \w find word characters. \w Find non-word characters. \d find numbers. \d to find non-numeric characters. \s Find white space characters. \s find non-whitespace characters. \b matches the word boundary. \b Matches a non-word boundary. To find the NUL character. \ nto find newline characters. \f Find a page break. \ r to find the carriage return character. \ t to find a tab. \v Find vertical tabs. \xxx finds characters that are specified in octal number XXX. \XDD finds the characters specified in hexadecimal number DD. \uxxxx finds Unicode characters that are specified in hexadecimal number xxxx. n+ matches any string that contains at least one n. n matches any string that contains 0 or more N. N? Matches any string that contains 0 or one n. N{x} matches a string containing a sequence of X N. N{x,y} matches a string containing a sequence of X or Y N. N{x,} matches a string that contains at least X N of a sequence. n$ matches any string that ends with N. ^n matches any string that begins with N.? =n matches any string that is immediately followed by the specified string n. n matches any string method that is not followed by the specified string N: Test retrieves the value specified in the string. Returns TRUE or FALSE. RegExp code var email = "[email protected]"; var reg =/^[a-z]+[a-z0-9_-]*\@[a-z0-9]+\. [A-z]+$/;alert (Reg.test (email));//true
JS's built-in object