<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
function arrReverse(num1, num2, num3, num4, num5) {
var num1 = parseFloat(prompt('请输入第1个数组数据:'));
var num2 = parseFloat(prompt('请输入第2个数组数据:'));
var num3 = parseFloat(prompt('请输入第3个数组数据:'));
var num4 = parseFloat(prompt('请输入第4个数组数据:'));
var num5 = parseFloat(prompt('请输入第5个数组数据:'));
var arr = [num1, num2, num3, num4, num5];
var newArr = [];
for (var i = arr.length - 1; i >= 0; i--) {
newArr[newArr.length] = arr[i];
}
return '数组' + '(' + num1 + ',' + num2 + ',' + num3 + ',' + num4 + ',' + num5 + ')' + '翻转后为:' +
newArr;
}
alert(arrReverse());
</script>
</head>
<body>
</body>
</html>
执行结果截图:
翻转数组结果.png
网友评论