I've been trying to generate a function to create an HTML table from an array of objects. This is the array that needs to be made into a table.
let units = [
    {
        'code': 'COMP2110',
        'title': 'Web Technology', 
        'offering': 'S1'
    },  
    {
        'code': 'COMP2010',
        'title': 'Algorithms and Data Structures', 
        'offering': 'S1'
    },
    {
        'code': 'COMP2150',
        'title': 'Game Design', 
        'offering': 'S1'
    },
    {
        'code': 'COMP2320',
        'title': 'Offensive Security', 
        'offering': 'S1'
    },
    {
        'code': 'COMP2200',
        'title': 'Data Science', 
        'offering': 'S2'
    },
    {
        'code': 'COMP2250',
        'title': 'Data Communications', 
        'offering': 'S2'
    },
    {
        'code': 'COMP2300',
        'title': 'Applied Cryptography', 
        'offering': 'S2'
    },
    {
        'code': 'COMP2000',
        'title': 'Object-Oriented Programming Practices', 
        'offering': 'S2'
    },
    {
        'code': 'COMP2050',
        'title': 'Software Engineering', 
        'offering': 'S2'
    },
    {
        'code': 'COMP2100',
        'title': 'Systems Programming', 
        'offering': 'S2'
    }
]
I've tried a function but I have no idea how to get it to work. I also have no idea how to get a query into the function.
function unit_table() {
    var totalRows = 3;
    var cellsInRow = 3;
    function drawTable() {
        // get the reference for the body
        var first = document.getElementById('first');
        // creates a <table> element
        var tbl = document.createElement("table");
        // creating rows
        for (var r = 0; r < totalRows; r++) {
            var row = document.createElement("tr");
            // create cells in row
            for (var c = 0; c < cellsInRow; c++) {
                m=0;
                var cell = document.createElement("td");
                var cellText = document.createTextNode(units[n][m]);
                cell.appendChild(cellText);
                row.appendChild(cell);
                m=m+1;
            }           
            n=n+1;
            tbl.appendChild(row); // add the row to the end of the table body
        }
        first.appendChild(tbl); // appends <table> into <first>
    }
    window.onload=drawTable; 
    // your code here
}
Any help would be greatly appreciated.
 
     
     
     
     
     
    