如何使用array fill in javascript显示用户输入的文字或数字?

How to use array fill in javascript showing the text or number inputed by the user?

所以我的一项任务是让用户输入他想要的任何内容,然后我必须用用户的输入填充数组,所以它基本上可以是 number/s 或文本。我不知道我是否应该使用 getelementbyid.value 或其他东西。

所以这是我目前的情况:

Fill1();

function Fill1() {
  var text1 = document.getElementById("smth").value;
}

function prfunc() {
  document.getElementById("answer").innerHTML = Fill1.fill(text1);
}
Type whatever you want: <input type="smth" id="smth"><br>
<button onclick="Fill1()">Fyll</button><br>
<div id="answer"></div>

尝试

let array = Array(10);

function Fill1() {
    array.fill(smth.value)
    prfunc();
}

function prfunc() {
    answer.innerText = array;
}
Type whatever you want: <input type="smth" id="smth"><br>
<button onclick="Fill1()">Fill</button><br>
<div id="answer"></div>

Rando 放在一边 - 如果您对浏览器支持有任何要求,我相信 array.fill 在 IE11 中不起作用。不知道任何其他浏览器,只是 运行 上周在一个项目上。

现在谁用IE11?显然我们有几千名客户。