javascript - My RegExp test is failing on 2nd iteration -


i have code want convert html entities [ &, <, >, ",' ] however, failing these 2 <>, on debugger, test becomes false, if switch them, first 1 works? code same ",' , why <> don't work?

function converthtml(str) {   // &colon;&rpar;   var = /[&]/ig;   var b = /[><><<>><]/ig;   var c = /["']/ig;   var e = str.split('');   var t = [];    function qw(item) {     return (item == '>') ? '&gt;' : '&lt;';   }    function fg(item) {     return (item == '"') ? '&quot;' : '&apos;';   }    (var x = 0; x < e.length; x++) {     var cv = e[x];     if (a.test(cv)) {       cv = '&amp;';       t.push(cv);     } else if (b.test(cv)) {       var er = qw(cv); // invoke function, error here, on second iteration       t.push(er);     } else if (c.test(cv)) {       var df = fg(cv);       t.push(df);     } else {       t.push(cv);     }   }   return t.join(''); } converthtml("><"); 


Comments