使用JavaScript在div中创建表

使用JavaScript在div中创建表,javascript,html,Javascript,Html,HTML 可能您可以从以下几点开始: let units=[{'code':'COMP2110','title':'Web技术','providing':'S1'},{'code':'COMP2010','title':'Algorithms and Data Structures','providing':'S1'}]; //先找到你的主管 const div=document.getElementById('first'); //为div构建HTML 让html=` ${Object.ke

HTML


可能您可以从以下几点开始:

let units=[{'code':'COMP2110','title':'Web技术','providing':'S1'},{'code':'COMP2010','title':'Algorithms and Data Structures','providing':'S1'}];
//先找到你的主管
const div=document.getElementById('first');
//为div构建HTML
让html=`
${Object.keys(units[0]).map(e=>`${e}`).连接(''')}
`
html+=`;
units.forEach(e=>html+=`
${Object.values(e.map)(v=>`${v}`).连接(''')}
`);
html+=`;
//向div添加HTML
div.innerHTML=html
表,th,td{
边框:1px纯黑;
}
Javascript
       <h1>Javascript Playground</h1>

        <div id="first"></div>
        <div id="second"></div>

    </body>
let units = [
    {
        'code': 'COMP2110',
        'title': 'Web Technology', 
        'offering': 'S1'
    },  
    {
        'code': 'COMP2010',
        'title': 'Algorithms and Data Structures', 
        'offering': 'S1'
    },

]