<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>遊戲選購</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<script>
var name = new Array("PS4","Switch","Xbox")
var price = new Array(9980, 12999, 11000)
var imgfile = new Array("ps4.jpg", "switch.jpg", "xboxone.jpg")
document.write("<table class='table table-hover'>");
document.write("<tr class='table-warning'>");
document.write("<td>品名</td>");
document.write("<td>單價</td>");
document.write("<td>產品圖示</td>");
document.write("</tr>");
for (var i = 0; i < name.length; i++) {
document.write("<tr>");
document.write("<td>" + name[i] + "</td>");
document.write("<td>" + price[i] + "</td>");
document.write("<td><img src='images/" + imgfile[i] + "' class='img-thumbnail' width='150'></td>");
document.write("</tr>");
}
document.write("</table>");
</script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
When I try to create an array name
with 3 items inside, the array splits into each letter instead of three elements only. In the table, I am going to show the three items in document.write("<td>" + name[i] + "</td>");
that each item uses a row instead of breaking each letter. Anyone knows where is the problem?