<scr1pt>
let hd =
[
{ title: "第一章走进JAVASCRIPT黑洞", lesson:18 }
{ title: " ubuntu19.10配置好用的编程I作站", lesson:29 }
{ title: " 媒体查询响应式布局", lesson:20 }
];
//写入表头
document.write(
<table border="1" width=" 100%">
<thead><tr><th>标题</ th><th>课程数量</ th></ thead>
)
//用for in循环遍历KEY索引,输出表格内容
for ( let i in hd ) {
document.write(
<tr><td>${hd. title}</ td><td>${hd[ i].lesson}<td></tr>;
}
document . write("</ table>");
直接取值比取索引更简单
//同样结果,用for of循环遍历VALUE循环输出表格内容
for ( vadio of hd ) {
document.write(
<tr><td>${vadio. title}</ td><td>${vadio.lesson}<td></tr>;
}
document . write("</ table>");
|