⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 js_obj_array.asp@output=print

📁 W3Schools tutorial..web designing
💻 ASP@OUTPUT=PRINT
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript Array Object</title>
 
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />

<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</head>
<body>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

<h1>JavaScript Array Object</h1>
<a href="js_obj_date.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_obj_boolean.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">The Array object is used to store a set of values in a single variable name.</p>
<hr />

<h2>Examples</h2>
<p>
<a target="_blank" href="tryit.asp@filename=tryjs_array">Create an array</a><br />
Create an array, assign values to it, and write the values to the output.</p>
<p><a target="_blank" href="tryit.asp@filename=tryjs_array_for_in">For...In 
Statement</a><br />
How to use a for...in statement to loop through the elements of an array.</p>
<p>
<a target="_blank" href="../jsref/tryit.asp@filename=tryjsref_concat">Join two 
arrays - concat()</a><br />
How to use the concat() method to join two arrays.
</p>
<p>
<a target="_blank" href="../jsref/tryit.asp@filename=tryjsref_join">Put array 
elements into a string - join()</a><br />
How to use the join() method to put all the elements of an array into a string.</p>
<p>
<a target="_blank" href="../jsref/tryit.asp@filename=tryjsref_sort">Literal array 
- sort()</a><br />
How to use the sort() method to sort a literal array.</p>
<p>
<a target="_blank" href="../jsref/tryit.asp@filename=tryjsref_sort2">Numeric array 
- sort()</a><br />
How to use the sort() method to sort a numeric array.</p>
<hr />

<h2>Complete Array Object Reference</h2>
<p>For a complete reference of all the properties and methods that can be used with 
the Array object, go to our <a href="../jsref/jsref_obj_array.asp">
complete Array object reference</a>.</p>
<p>The reference contains a brief description and examples of use for each 
property and method!</p>

<hr />

<h2>Defining Arrays</h2>
<p>The Array object is used to store a set of values in a single variable name.</p>
<p>We define an Array object with the new keyword. The following code line 
defines an Array object called myArray:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table5">
    <tr>
      <td>
        <pre>var myArray=new Array()</pre>
      </td>
    </tr>
</table>
<p>There are two ways of adding values to an array (you can add as many values 
as you need to define as many variables you require).</p>
<p>1:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table1">
    <tr>
      <td>
        <pre>var mycars=new Array();
mycars[0]=&quot;Saab&quot;;
mycars[1]=&quot;Volvo&quot;;
mycars[2]=&quot;BMW&quot;;</pre>
      </td>
    </tr>
</table>
<p>You could also pass an integer argument to control the array's size:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table4">
    <tr>
      <td>
        <pre>var mycars=new Array(3);
mycars[0]=&quot;Saab&quot;;
mycars[1]=&quot;Volvo&quot;;
mycars[2]=&quot;BMW&quot;;</pre>
      </td>
    </tr>
</table>
<p>2:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table2">
    <tr>
      <td>
        <pre>var mycars=new Array(&quot;Saab&quot;,&quot;Volvo&quot;,&quot;BMW&quot;);</pre>
      </td>
    </tr>
</table>
<p><b>Note:</b> If you specify numbers or true/false 
values inside the array then the type of variables will be numeric or Boolean instead 
of string.</p>
<hr />

<h2>Accessing Arrays</h2>
<p>You can refer to a particular element in an array by referring to the name of 
the array and the index number. The index number starts at 0.</p>
<p>The following code line:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table6">
    <tr>
      <td>
        <pre>document.write(mycars[0]);</pre>
      </td>
    </tr>
</table>
<p>will result in the following output:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table7">
    <tr>
      <td>
        <pre>Saab</pre>
      </td>
    </tr>
</table>
<br />
<hr />

<h2>Modify Values in Existing Arrays</h2>
<p>To modify a value in an existing array, just add a new value to the array 
with 
a specified index number:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table10">
    <tr>
      <td>
        <pre>mycars[0]=&quot;Opel&quot;;</pre>
      </td>
    </tr>
</table>
<p>Now, the following code line:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table13">
    <tr>
      <td>
        <pre>document.write(mycars[0]);</pre>
      </td>
    </tr>
</table>
<p>will result in the following output:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table14">
    <tr>
      <td>
        <pre>Opel</pre>
      </td>
    </tr>
</table>
<br />

<hr />
<a href="js_obj_date.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_obj_boolean.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -