Search code examples
javascriptarraysfunctiongetelementbyid

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


So one of my assignments is about that I should let the user type whatever he wants and then I have to fill the array with the input from the user, so it's basically could be number/s or text. I don't know if I should use getelementbyid.value or something else.

SO here´s what I have so far:

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>


Solution

  • Rando aside - I believe array.fill doesn't work in IE11, if you have any requirements around browser support. Dunno about any other browsers, just ran into that last week on a project.

    Who uses IE11 nowadays? Apparently a few thousand of our customers.