简体   繁体   中英

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

 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>元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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