JS Learning (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.