Files
Course/Web/test8/opreaArr.html
2025-12-09 09:11:22 +08:00

43 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 id="output"></h1>
<script>
const output = document.getElementById("output");
// 通过for循环创建一个包含1到20数字的数组numbers
let numbers = new Array();
for (let i = 1; i <= 20; i++) {
numbers.push(i);
}
// 定义doubleNumbers函数用于将数组元素乘以3并返回新数组
const doubleNumbers = (a) => {
return a.map((value) => value * 3);
}
// 调用doubleNumbers函数传入numbers数组得到处理后的数组并赋值给doubledoutput变量
const doubledOutput = doubleNumbers(numbers);
// 通过id获取页面上id为"output"的h1标签元素并将其赋值给outputElement变量
output.innerHTML += "numbers: " + numbers + "<br/>";
// 定义一个函数displayOutput用于将数组元素以字符串形式展示在h1标签中
const displayOutput = (a) => {
return a.join(" ");
}
output.innerHTML += "displayOutput(): " + displayOutput(numbers) + "<br/>";
// 将doubledoutput数组中的元素以字符串的形式显示在h1标签中
output.innerHTML += "doubledoutput: " + doubledOutput + "<br/>";
</script>
</body>
</html>