Printing each value of an array on a separate line Javascript

后端 未结 2 1173
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 18:42

I have a program that involves Javascript to allow for interaction with a webpage. It\'s a baseball site so what I am doing is prompting the user to enter a month. The user

2条回答
  •  孤街浪徒
    2021-01-15 19:14

    You can use .join() to combine the array into one string, and separate each entry by
    :

    document.getElementById("result").innerHTML =
      schedule.join("
    ");

    There's no need for the self-closing / in
    . More important, there's no need for the for loop. That code above will do the whole thing.

    If you want a
    after the last entry, just add it:

    document.getElementById("result").innerHTML =
      schedule.join("
    ") + "
    ";

提交回复
热议问题