Create table for email content from array of objects.

Let variable arraOfObjects be an array containing objects. To convert it into table for email use the code below.

function createTable(arraOfObjects) {
    try {
        for (let i of arrayDet) {
            tableRows += `<tr><td style="border-bottom: 1px solid black;border-right: 1px solid black;">${i.Key1}</td><td style="border-bottom: 1px solid black;border-right: 1px solid black;">${i.key2}</td><td style="border-bottom: 1px solid black;border-right: 1px solid black;">${i.key3}</td><td style="border-bottom: 1px solid black;border-right: 1px solid black;">${i.key4}</td></tr>`;
        }
        return tableRows
    } catch (e) {
        log.error("error@createTable", e);
    }
}
const tableHeader = `<tr><th style="border-bottom: 1px solid black;border-right: 1px solid black;">Heading1</th><th style="border-bottom: 1px solid black;border-right: 1px solid black;">Heading2</th><th style="border-bottom: 1px solid black;border-right: 1px solid black;">Heading3</th><th style="border-bottom: 1px solid black;border-right: 1px solid black;">Header4</th></tr>`;
let irQtyTableContent = createTable(arraOfObjects);
let tableContentI = `<table align="center" style="sans-serif;border-collapse: collapse;width: 100%;border: 1px solid black">${tableHeader}${irQtyTableContent}</table>`;

Leave a comment

Your email address will not be published. Required fields are marked *