Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scoreToHtml(scoreStr) {
- let scoreArr = JSON.parse(scoreStr);
- let html = '<table>\n';
- html += `\t<tr><th>name</th><th>score</th>\n`;
- function htmlEscape(text) {
- text = text.toString();
- let map = {'"': '"', '&': '&', "'": ''', '<': '<', '>':'>'};
- return text.replace(/[\"&'<>"]/g, ch => map[ch]);
- }
- for (let score of scoreArr){
- html += '\t<tr>';
- html += `<td>${htmlEscape(score['name'])}</td><td>${htmlEscape(score['score'])}</td>`;
- html += `</tr>\n`;
- }
- html += '</table>';
- return html;
- }
- console.log(scoreToHtml(['[{"name":"<div>Pesho","score":479},{"name":"Gosho","score":205}]']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement