1 Array Objects
The function is to store a series of values using a separate variable name.
1.1 Create a new array:
var mycars = new Array ()
Mycars[0] = "Saab"
MYCARS[1] = "Volvo"
MYCARS[2] = "BMW"
1.2 For in Declaration
for (x in Mycars)
{
document.write (Mycars[x] + "<br/>")
}
1.3 Merging arrays
var arr = new Array (3)
Arr[0] = "George"
ARR[1] = "John"
ARR[2] = "Thomas"
var arr2 = new Array (3)
Arr2[0] = "James"
ARR2[1] = "Adrew"
ARR2[2] = "Martin"
var arr3 = Arr.concat (ARR2)
document.write (ARR3)
Output: George,john,thomas,james,adrew,martin
1.4 Generating a String join
var str = Arr.join ()
George,john,thomas
var str = arr.join (".")
George.John.Thomas
1.5 Sorting array sort
function Sortnumber (A, B)
{
Return a<b
}
var arr = new Array (6)
Arr[0] = "George"
ARR[1] = "John"
ARR[2] = "Thomas"
ARR[3] = "James"
ARR[4] = "Adrew"
ARR[5] = "Martin"
document.write (arr + "<br/>")
document.write (Arr.sort (Sortnumber))
Arr.sort () Default ascending sort
2 message Box 2.1 alert box alert
Alert ("Say Hello again to you!") Here, we show you how to add a line to a warning box by "+ \ n ' +". ")
2.2 Confirmation Box Comfirm
Confirm ("Press a button!");
2.3 Hint Box prompt
Prompt ("Please enter your name", "Bill Gates")
3 Cookie 3.1 Create and store cookies
function Setcookie (c_name,value,expiredays) {var exdate=new Date () exdate.setdate (Exdate.getdate () +expiredays) document.cookie=c_name+ "=" +escape (value) + ((expiredays==null)? "": "; expires=" +exdate.togmtstring ())}
3.2 Getting cookies
function GetCookie (c_name) {if (document.cookie.length>0) { c_start=document.cookie.indexof (c_name + "=") if (c_start!=-1) { C_start=c_start + c_name.length+1 c_end=document.cookie.indexof (";", C_start) if (c_end==-1) c_end=document.cookie.length return unescape (document.cookie.substring (c_start,c_end)) } } Return ""}
JS Learning (ii)