webproger > cheat sheets > JavaScript
 
Songs in Easy English
 
charAt, charCodeAt, fromCharCode
<!DOCTYPE html><html><head>
</head><body>
<script>
  var c = 3;
  var s = "대한민국";
  for(i=0; i<s.length; i++) {
    document.write(s.charCodeAt(i));
    document.write(' ');
    document.write(s.charAt(i));
    document.write('<br>');
  }
  var ...
22#742 SIBLINGS CHILDREN 742
 
charCodeAt, fromCharCode
s = '대한민국\nKorea';
s = s.replace("\n","\\n");
for(i=0; i<s.length; i++) {
  n = s.charCodeAt(i);
  c = String.fromCharCode(n);
  document.write('<br>'+n+' '+c);
}
22#2634 SIBLINGS CHILDREN 2634
 
exec
<script>
  var s = "JavaScript MySQL";
  var r = /[0-9a-z]+/g;
  while(a=r.exec(s)) {
    document.write('<br>'+a);
  }
</script>

ava
cript
y
22#2630 SIBLINGS CHILDREN 2630
 
RegExp, match, replace
function sv(v) {
  var r = new RegExp("&s=[0-9]+");
  if(window.location.href.match(r))
       window.location.href = window.location.href.replace(r,"&s="+v);
  else window.location.href = window.location.href+"&s="+v;
}

var ur = document.getElementById( ...
22#3499 SIBLINGS CHILDREN 3499
 
setTimeout
s = '';
i = 0;
function f1( ) { s += ' B'+i; }
function f2(j) { s += ' C'+j; }

window.setTimeout("s += ' A'+i;",1000);
window.setTimeout(f1( ),2000);
window.setTimeout(f2(i),3000);
i++;
// B0 C0 A1


function r() {
  window.setTimeout("s += ' A'+i;",1000 ...
22#253 SIBLINGS CHILDREN 253

-