<!DOCTYPE html>
<html>
<head>
<title>js5.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<!-- 这是一种方式
<script type="text/javascript">
var fruit = new Array("苹果","香蕉","栗子");
for(var i = 0; i<fruit.length; i++){
document.writeln("fruit[" +i+ "]" + "=" + fruit[i] + "<br>");
}
-->
<!-- 推荐使用这种方式
<script type="text/javascript">
var fruit = ["苹果","橘子","鸭梨"];
for(var i = 0; i<fruit.length; i++){
document.writeln("fruit[" + i + "]" + "=" + fruit[i] + "<br>");
}
-->
<!-- 这是又一种方式实现数组 -->
<script type="text/javascript">
var fruit = new Array();
fruit.push("毛");
fruit.push("毛2");
fruit.push("毛3");
for(var i=0; i<fruit.length;i++){
document.writeln("fruit["+i+"]=" +fruit[i] + "<br>");
}
</script>
</body>
</html>
javascript 数组的定义及使用方法
最新推荐文章于 2021-09-03 11:21:24 发布