;(function update_tree(jsonml) {  for(i = 1; i < jsonml.length; i++) {    if(jsonml[i][0] === 'para' && typeof jsonml[i][1] === string && jsonml[i][1].match(//g)) {      // some code    }    if(jsonml[i][0] === 'hr') {      // some code    }    if(jsonml[i][0] === 'h2') {      // some code    }  }})(tree)What the code does is to take a JsonML tree like this:[ 'markdown',  [ 'para', 'This is a ', [ 'em', 'test' ] ],  [ 'hr' ],  [ 'para', 'another test' ],  [ 'para', 'and te fen eternte t' ],  [ 'hr' ],  [ 'para', 'ert wte wet wntwet wte w' ] ]And modify the data in it. For instance, the fist if statement checks for paras with double quotes. I'll have many of these if statements, say, to check for h3, h4 tags or other HTML entities.
Should I change the following to switch or else if statements?
javascript
else if would be more efficient because it wouldn't continue to evaluate comparisons that you already know won't match.  It would also be more efficient to cache some values here so you aren't revaluating the same expression over and over.A switch statement could work fine.  I would tend to use a switch or an object table lookup if you had lots of different tag names you were looking for.  At just qty 3, I'd probably stick to the else if.Here's an implementation with else if and some expression caching:;(function update_tree(jsonml) {    var item, tag;    for (i = 1; i < jsonml.length; i++) {        item = jsonml[i];        tag = item[0];        if (tag === 'para') {            if (typeof item[1] === string && item[1].match(//g)) {                console.log(item);                item[1] = item[1].replace(//g, );            }        } else if (tag === 'hr') {            var p = jsonml[i + 1];             item.splice(0, 1, 'para', '* * *');             p.splice(1, 0, {'class': 'noind'});        } else if (tag === 'h2') {            // do stuff        }    }})(tree);If there were many, many tags, I would use a table lookup:(function(tree) {    var tagOps = {        para: function(item) {            // code here        },        hr: function(item) {            // code here        },        h2: function(item) {            // code here        }    };    var item, fn;    for (i = 1; i < tree.length; i++) {        item = tree[i];        fn = tagOps(item[0]);        if (fn) {            fn(item);        }    }})(tree);