Is there a more succinct way of writing this simple JavaScript loop? This seems a bit redundant to me, but I'm not sure of how else I might be able to write this.  Normally I'd use a switch statement, but I don't think that'll work here.  I realize I could also do this in a for loop, but the main heart of the question is what's inside the loop itself.  "arr" is an array, just in case it's not obvious.

var i = 0, x = arr.length;

while (i &lt; x) {
    if (typeof arr[i] === 'object' &amp;&amp; !Array.isArray(arr[i])) {
        attr = arr[i];
    }
    else if (typeof arr[i] === 'string') {
        text = arr[i];
    }
    else if (typeof arr[i] === 'object' &amp;&amp; Array.isArray(arr[i])) {
        child = arr[i];
    }
    i++;
}
I think at the very least I'd rearrange the cases to make the dichotomy between Array.isArray and !Array.isArray more direct and apparent:

while (i &lt; x) {
    if (typeof arr[i] === 'string') {
        text = arr[i];
    }
    else if (typeof arr[i] === 'object') {
        if (Array.isArray(arr[i])) {
            child = arr[i];
        }
        else {
            attr = arr[i];
        }
    }
    i++;
}


That's not really a lot shorter but I think it makes the intent rather more clear (at least assuming I've divined the real intent correctly).