Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
What is an array?
Numerical values may be stored comprise strings, numbers, time, Chinese, variables, constants, etc., used for storing variables, array object is to effect: a separate variable names used to store a series of values;
How to create an array?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
//声明变量i
var i;
//创建数组
var mycars = new Array();
//声明变量a的值为(变量)
var a="变量";
// 数字
mycars[0] = 1
// 英文
mycars[1] = "number";
// 字符串
mycars[2] = "。:”》《";
// 变量
mycars[3] = a;
// 循环输出数组
for (i=0;i<mycars.length;i++){
document.write(mycars[i] + "<br />");
}
</script>
</head>
<body>
</body>
</html>
Facts have proved that digital does not require a semicolon and quotation marks can be declared, the string needs quotation marks and semicolons, semicolon variables need not require quotes, quotes browser mistaken for a string
Simple way
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
// 声明变量i
var i;
// 新建数组并赋值
var mycars=new Array("Saab","Volvo","BMW");
// 循环输出数组
for (i=0;i<mycars.length;i++){
document.write(mycars[i] + "<br />");
}
</script>
</head>
<body>
</body>
</html>
Such an approach would be more simple and can be very effective in reducing the amount of code and browsers efficiency