one, Array Object
Arrayobject.reverse () flips the array
Arrayobject.shift () Deletes the first element in the array and returns it
Arrayobject.unshift ( element 1, element 2) adds one or more array elements to the beginning of the array and returns the length of the new array
Arrayobject.pop () Deletes the last element of the array and returns it
Arrayobject.push () adds one or more array elements to the end of the array and returns the new length
Arrayobject.sort (sortby) Sorting an array element
second, Date Object
first: use the new keyword with date () to create a parameter with (return a specified time and Date)
second: use the new keyword with date () to create without parameters (returns the current specified Date)
Date Method Instance<script type= "text/javascript" >//Create a time Date object varToday =NewDate (); //gets the 4-digit year from this object varYear =Today.getfullyear (); varm = Today.getmonth () +1; vart =today.getdate (); varxs =today.gethours (); varFZ =today.getminutes (); varms =Today.getseconds (); varHMS =Today.getmilliseconds (); varSJC =Today.gettime (); //defines a string to output varstr = "; STR+ = "this Year is:" +year ; STR+ = "<br/> Month is:" +I (m); STR+ = "<br/> Today is:" +I (t); STR+ = "<br/> Current hour:" +I (xs); STR+ = "<br/> Current minute:" +I (fz); STR+ = "<br/> Current number of seconds:" +I (ms); STR+ = "<br/> Current millisecond:" +I (hms); STR+ = "<br/> Current timestamp:" +SJC document.write (str); //Leading 0 functionI (y) {returny<10? "0" +y:y; } </script>
third, the Math Object
The Math object does not need to be created for direct use .
Math.Abs (x) to find the absolute value of x
Math.ceil (x) Upward rounding of X
Math.floor (x) to perform a downward rounding of X
Math.max (n1,n2,n3) Returns the maximum number
Math.min (n1,n2,n3) Returns the smallest number
Math.sqrt (x) returns the square root of x
Math.pow (x, y) returns the x- Square
Math.Round (x) rounding x
Math.random () returns a random number between 0~1 contains 0 but does not contain 1[0,1]
<script type= "text/javascript" > // ask for a random number to encapsulate it into a function // This function needs to have two values one is the maximum one is the minimum function getrandom (a, b) {return Math.floor (math.random () * (a-b+1) +b); } // document.write (getrandom (20,10)); </script>
Iv. Methods for Window objects
Window.alert () pops a warning prompt to the Browser's window
Window.prompt () pops an input dialog box into the Browser's window
Window.confirm () pops up a confirmation dialog to the browser window and clicks The "ok" button to get the boolean true, and clicking the "cancel" button will give the Boolean type false
window.open (url,name,options) opens a new window
Window.close () to close the current window
Window.settimeout (CODE,MILLISEC) timer: executes code once the specified time is up. code: Execution of the JS code, millisec: number of milliseconds
Window.cleartimeout ( to clear the return value of the delay ) clears the timer
Window.setinterval (CODE,MILLISEC) timer: executes code code at every time
Window.clearinterval ( the Timer return value to clear ) clears the timer
Dynamic Clock:<style type= "text/css" >div{width:400px; height:200px; line-height:200px; Text-align:center; background:skyblue; margin:100px auto; } </style> <script type= "text/javascript" >functionGetweek (week) {varstr = "week"; Switch(week) { case1: Str+ = "one"; break; case2: Str+ = "two"; break; case3: Str+ = "three"; break; case4: Str+ = "four"; break; case5: Str+ = "five"; break; case6: Str+ = "six"; break; default: Str+ = "day"; break; } returnstr; } functionI (y) {returny<10? "0" +y:y; } //every second to update a time every second to get back to the time functiongetclock () {//Create a time Date object varToday =NewDate (); vary =Today.getfullyear (); varm =Today.getmonth (); varD =today.getdate (); varh =today.gethours (); varf =today.getminutes (); vars =Today.getseconds (); varW =Today.getday (); varstr = y+ "-" + i (m) + "-" +i (d) + " " +i (h) + ":" +i (f) + ":" +i (s) + " " +Getweek (w); //You need to write to the div to get the HTML tag before you write it.document.getElementById ("div"). InnerHTML =str; } //after the page is loaded, execute the code inside.Window.onload =function(){ //every second to use the timer every second to request Getclock () The function of this function will be every second to get the system timeSetInterval ("getclock ()", 1000); } </script>JavaScript Learning 4