简体   繁体   English

如何在JS中显示数字二维数组

[英]How to display a numeric Two dimensional array in JS

So I'm having the following code to print an array in the console log it returns the expected value in line but when in innerHtml it just does not print as if it were an Two dimensional array所以我有以下代码在控制台日志中打印一个数组,它返回预期的值,但是当在innerHtml中时,它不会像二维数组一样打印

 var matrix = []; for(var i=0; i<2; i++) { matrix[i] = []; for(var j=0; j<2; j++) { matrix[i][j] = i; document.getElementById('hassianaJ').innerHTML += '<tr><th scope="row">' +matrix[i][j] + '</th></tr>'; } }
 <!doctype html> <head> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <head> <body> <div class="col-md-12 mt-5"> <table class="table"> <thead id="hassiamaI"> </thead> <tbody id="hassianaJ"> </tbody> </table> </div> </body> </head>

您没有关闭<th>元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM