Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function jsonTable(input) {
- let html = '<table>\n';
- const htmlEscape = (text) => {
- const map = {
- '"': '"',
- '&': '&',
- "'": ''',
- '<': '<',
- '>': '>',
- };
- return text.replace(/[\"&'<>]/g, (ch) => map[ch]);
- };
- input.forEach((line) => {
- const obj = JSON.parse(line);
- html += ' <tr>\n';
- html += ` <td>${htmlEscape(obj.name)}</td>\n`;
- html += ` <td>${htmlEscape(obj.position)}</td>\n`;
- html += ` <td>${obj.salary}</td>\n`;
- html += ' </tr>\n';
- });
- html += '</table>';
- console.log(html);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement