How to create a table using html in script

We can use the HTML elements to create a table in the script. We can use the script values as table data. Here the data as the objets.

try {

                let tableHtml = ‘<br><br><table style=”border-collapse: collapse; border=1″><tbody>’;

                tableHtml += ‘<tr style=”background-color:#C0C0C0;text-align:center;”>’;

                tableHtml += `<td ><b> Questions</b></td>` + `<td> <b>Responses</b> </td>`;

                tableHtml += `</tr>`;

                //Create the table

                for (let fieldLabel in data) {

                    if (checkForParameter(data[fieldLabel])) {

                        tableHtml += `<tr>`;

                        tableHtml += `<td style=”border: 1px solid black; padding: 8px;”>${fieldLabel}</td>`;

                        tableHtml += `<td style=”border:  1px solid black; padding: 8px;”>${data[fieldLabel]}</td>`;

                        tableHtml += ‘</tr>’;

                    }

                }

                tableHtml += ‘</tbody></table>’;

               

            } catch (error) {

                log.error(“error@createHtmlTable”, error);

                return ;

            }

       

Leave a comment

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