Je rencontre des problèmes pour afficher les valeurs de tableau dans le tableau que j'ai créé sous le programme. J'ai créé l'instance d'objets et de tableaux de ces instances. J'ai utilisé pour la boucle pour afficher les valeurs dans le tableau mais obtenir l'erreur: Quelqu'un peut-il m'aider à identifier un problème?Meilleure façon d'afficher des valeurs de tableaux multidimensionnels dans une table en javascript
résultat attendu:
https://i.stack.imgur.com/knetX.jpg
myoutput:
https://i.stack.imgur.com/UqDgC.png
<html>
<head>
<title></title>
<script type="text/javascript">
function Cruise(cruise_Date, cruise_Destination, cruise_URL, ship_Name, ship_Description, ship_url, the_price) {
this.cruise_Date = cruise_Date;
this.cruise_Destination = cruise_Destination;
this.cruise_URL = cruise_URL;
this.ship_Name = ship_Name;
this.ship_Description = ship_Description;
this.ship_url = ship_url;
this.price = the_price
}
function DisplayList(cruise_Date, cruise_Destination, ship_Name, the_price) {
this.date = cruise_Date;
this.destination = cruise_Destination;
this.ship = ship_Name;
this.price = the_price;
this.display = displayClass;
}
function displayClass(){
document.write(this.date);
document.write(this.destination);
document.write(this.ship);
document.write(this.price);
}
var myCruise = new Cruise("13 Oct 2018",
"<a href ='#'> 3 Night Bahmas cruise </a>",
"Royal Caribbean",
'$' + 179);
var myCruise2 = new Cruise("13 Oct 2018",
"<a href = '#'> 4 Nights Baja Mexico Itinerary </a>",
"Carnival Inspiration",
'$' + 179);
var myCruise3 = new Cruise("13 Oct 2018",
"<a href = '#'>5 - Night Alaskan Cruise from Vancouver </a>",
"Disney Cruise Line",
'$' + 179);
instances = new Array(myCruise, myCruise2, myCruise3);
list = new Array("Departs", " Destination ", "Ship", "Price from");
</script>
</head>
<body>
<table border="", align="center", cellpadding="8" >
<thead>
<tr>
<script type="text/javascript">for (i = 0; i < 4; i++) {
document.write('<th>'+ list[i] +'</th>');
}
</script>
</tr>
</thead>
<tbody>
<tr>
<script type="text/javascript">
for (j = 0; j < 4; j++) {
document.write('<td>' + instances[j] + '</td>');
}
</script>
</tr>
</tbody>
</table>
</body>
</html>