Create dynamic html table using javascript from simple array

后端 未结 3 921
暖寄归人
暖寄归人 2021-01-19 08:02

I want to write some JavaScript to create a simple HTML table from an array that just contains numbers:

var array = [1,2,3,4,5,6,7,8,9,10];

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 08:24

    var array = [1,2,3,4,5,6,7,8,9,10];
    
    var result = "";
    result += "";
    for (var j = 0; j < array.length; j++) {
      result += "";
      if ((j + 1) % 5 == 0) {
        result += "";
      }
    }
    result += "";
    result += "
    " + array[j] + "
    "; document.body.innerHTML = result;

    Please give it a try if that works

提交回复
热议问题