Pages

Map en action

let p = '<h1>escapeForHTML<h1>';



let regex = /[<>&]/gi;



let r = new Map([
  ['>','&gt;'],

  ['&','&amp;'],

  ['<', '&lt;'],

]);


let f = c => r.get(c)


document.body.insertAdjacentHTML("afterbegin",p);

document.body.insertAdjacentHTML("afterbegin",p.replace(regex,f));