JavaScript.js
function myreverse(arr) {
for (var i = arr.length - 1;i>=0;i--) {
var temp = arr[i];
alert(temp);
arrTwo.push(temp);
alert(arrTwo);
}
}
var arr = new Array();
arr[0] = "3";
arr[1] = "a";
arr[2] = "8";
arr[3] = "haha";
var arrTwo = new Array();
然后在HTML中调用它
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JS基础</title>
<script src="JavaScript.js" type="text/javascript"></script>
<!--求最大值--><!--<script type="text/javascript">
function getMax(arr) {
var max = arr[0];
for (var i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
var arr1 = new Array();
arr1[0] = 20;
arr1[1] = 10;
arr1[2] = 21;
alert(getMax(arr1))
</script>-->
<script type="text/javascript">
myreverse(arr);<!--调用.js中的方法-->
</script>
</head>
<body>
</body>
</html>