JavaScript Asignación del número de índice a la fila en la tabla

var rows = tbl.rows; n = 1;
for (i=0; i<rows.length; i++) {
  row = rows[i];
  f = row.firstElementChild;
  if (f) {
    el = document.createElement(f.tagName);
    el.innerHTML = (f.tagName == "TH") ? "#" : n;
    row.insertBefore(el, f);
    if (f.tagName != "TH") n++;
  }
}
SAMER SAEID