Note Contents Map:
A. JS String object
- View the W3cschool document, which has a detailed property method for that object.
- Common methods
- HTML-related methods
- Bold (): Use bold to display the string.
<script type= "Text/javascript" > var str= "Hello world!" document.write (Str.bold ()) //helloworld! Show as bold "find statement end without semicolon can also run successfully qaq"</script>
- FontColor (): Displays the string using the specified color.
<script type= "Text/javascript" > var str= "Hello world!" document.write (Str.fontcolor ("Red"))</script>
- FontSize (): Displays a string using the specified dimensions
<script type= "Text/javascript" > var str= "Hello world!" document.write (str.fontsize (7))</script>
- Link (): Displays the string as a link.
<script type= "Text/javascript" > var str= "This is a URL" document.write (Str.link ( "http://www.w3school.com.cn"))</script>
- Sub (): Displays the string as subscript. SUP (): Displays the string as superscript.
<script type= "Text/javascript" > var str= "Hello world! subscript" document.write (Str.sub ()) var str1= "Hello world! superscript" document.write (Str1.sup ())</script>
- Java-like method ()More examples Usage view documents
- Concat (): Connection string.
- CharAt (): Returns the character at the specified position.
- IndexOf (): Retrieves a string. That is, returns the character position
- Split (): Splits a string into an array of strings.
- Replace (): Replaces a substring that matches a regular expression.
- SUBSTR () substring ():
<script type= "Text/javascript" >//Concat Method varSTR1 = "ABC"; varstr2 = "DFG"; document.write (Str1.concat (str2)); document.write ("); //Charat Method varSTR3 = "ABCDEFG"; document.write (Str3.charat (20));//character position does not exist, returns an empty stringdocument.write (Str3.charat (3)); document.write ("); //IndexOf Method varSTR4 = "Poiuyt"; document.write (Str4.indexof ("Y")); document.write (Str4.indexof ("W"));//character does not exist, return-1document.write ("); //Split Method "More example Usage view documents" varSTR5 = "A-b-c-d"; vararr1 = Str5.split ("-"); document.write ("Length:" +arr1.length + "<br/>"); varStr= "How is you doing today?"document.write (Str.split ("") + "<br/>") document.write (Str.split ("") + "<br/>") document.write (Str.split ("", 3)) document.write ("); //Replace Method "More example Usage view documents" varSTR6 = "ABCD"; document.write (STR6); document.write ("<br/>"); document.write (Str6.replace ("A", "Q")); Pass two parameters, the first original character, and the second is the character to be replaced by document.write ("); //substr Method varSTR7 = "Abcdefghuiop"; document.write (Str7.substr (5,5));//Fghui starts at fifth place and intercepts severaldocument.write ("); //substring Method varStr8 = "Abcdefghuiopqrst"; document.write (Str7.substring (3,5));//de from the beginning of the first to the end of the [3,5) package left without packet right</script>
It is important to note that the JavaScript string is immutable (immutable), and the method defined by the string class cannot alter the contents of the string. A method like String.touppercase () returns a completely new string instead of modifying the original string.
Second, JS of the array object
- Common Properties
- Common methods
- Concat (): Joins two or more arrays and returns the result.
- The method does not alter the existing array, but only returns a copy of the concatenated array. That is, a new array is returned.
- Join (): puts all the elements of the array into a string. element is delimited by the specified delimiter.
- Push (): Adds one or more elements to the end of the array and returns the new length.
- The push () method adds its parameter order to the tail of the arrayobject. It modifies the arrayobject directly, rather than creating a new array. The push () method and the Pop () method use the advanced post-stack functionality provided by the array.
- If you add an array, add the array as a whole string at this time.
- Pop (): Delete and return the last element of the array
- The Pop () method removes the last element of the arrayobject, reducing the length of the array by 1, and returning the value of the element it deletes. If the array is already empty, pop () does not change the array and returns the undefined value.
- Reverse (): Reverses the order of the elements in the array.
- The method changes the original array without creating a new array.
<script type= "Text/javascript" >//Concat Method varARR1 = [A]; varARR2 = [4,5,6]; varARR3 = [7,8,9]; document.write (Arr1.concat (ARR2)+ "<br/>");//1,2,3,4,5,6document.write (Arr1.concat (ARR2,ARR3));//1,2,3,4,5,6,7,8,9document.write ("); //Join Method varARR4 =NewArray (3) arr4[0] = "George"arr4[1] = "John"arr4[2] = "Thomas"document.write (Arr4.join ()+ "<br/>")//George,john,thomasdocument.write (Arr4.join ("."))//George.John.Thomasdocument.write ("); //Push Method varARR5 =NewArray (3); arr5[0] = "Tom"; arr5[1] = "Lucy"; arr5[2] = "Jack"; document.write ("Old array:" +ARR5); document.write ("<br/>"); document.write ("Old length:" +arr5.length); document.write ("<br/>"); document.write ("New Length:" +arr5.push ("Zhangsan")); document.write ("<br/>"); document.write ("New array:" +ARR5); document.write ("<br/>", "<br/>"); varARR6 = ["www", "QQQ"]; varARR7 = ["AAA", "BBB", "CCC"]; document.write ("Old array:" +ARR6 + "<br/>"); document.write ("Old length:" +arr6.length + "<br/>"); document.write ("New Length:" +arr6.push (ARR7) + "<br/>");//The result 3 is not 5 because the ARR7 is added to the ARR6 as a whole string (that is, an element)document.write ("New array:" +ARR6); for(vari=0;i<arr6.length;i++) {alert (arr6[i]); } document.write ("); //Pop Method varARR8 = ["Zhangsan", "Lisi", "Wangwu", "Zhaoliu"]; document.write ("Old array:" +ARR8 + "<br/>"); document.write ("Return:" +arr8.pop () + "<br/>"); document.write ("New array:" +arr8); document.write ("); //Reverser Method varARR9 = ["Zhangsan1", "Lisi1", "zhaoliu1", "Niuqi1"]; document.write ("Old array:" +ARR9); document.write ("<br/>"); document.write ("New array:" +arr9.reverse ());</script>
Third,the date object of JS
- Get current time in Java
Date date = new Date (); // tolocalestring () // xxxx year xx month xx day xx:xx:xx
- js inside get current time
<script type= "Text/javascript" > // get current time var date = new Date (); document.write (date); // Sat 22:33:17 gmt+0800 ( Chinese standard Time) // Convert to custom format document.write (" // May 28, 2016 22:33:17 </ Script>
- Gets the current year method getFullYear ()
New Date ();d ocument.write ("Year:" +date.getfullyear ()); //
- Gets the current month method GetMonth ()
<script type= "Text/javascript" > // return is 0月-November, if you want to get the exact value, add 1 var New Date (); var date1 = Date.getmonth () +1; document.write ("Month:" +date1); </script>
- get current Week getday ()
<script type= "Text/javascript" > // return (0 ~ 6) // foreign friends, Sunday as the first day of the week, Sunday returned is 0, and Monday to Saturday returned is 1-6 var date = new Date (); document.write ( "Week:" +date.getday ()); </script>
- Gets the current day getDate ()
<script type= "Text/javascript" > // get current day 1-31 varnew Date (); document.write ("Day:" +date.getdate ()); </script>
- Gets the current hour getHours ()
<script type= "Text/javascript" > // get current hour 0~23 var New Date (); document.write ("Hour:" +date.gethours ()); </script>
- Gets the current minute getminutes ()
<script type= "Text/javascript" > varnew Date (); document.write ("minute:" +date.getminutes ()); </script>
- Gets the current seconds getseconds ()
var New Date ();d ocument.write ("Second:" +date.getseconds ());
- gets the number of milliseconds getTime () "Returns the number of milliseconds that are 1970 1 1 to date" settime () sets the time based on the number of milliseconds
var New Date (); document.write ("Second:" +date.gettime ());
Four, JS Math object
The global function of the five and JS
Overloading of functions of the six and JS
Iv. JavaScript Basics &dom