Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function convertHTML(str) {
- // Reg Exp for patterns across the entire str
- var regExp = [/&/g, /</g, />/g, /"/g, /'/g];
- var chars = ['&', '<','>','"',"'"];
- // search and replace loop
- for(var i = 0; i < chars.length; i++){
- str = regExp[i][Symbol.replace](str, chars[i]);
- }
- return str;
- }
- // JS is superior to the "snake"
- convertHTML("JS is superior to the 'snake'");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement