Turning a 2D array into a tree
I was also facing similar issue where I needed to convert the 2-D array to a tree structure. This code might help.:)

var tree = data.reduce(function(tree, item) {
    var tempTree = tree;
    for(var i=0;i&lt;item.length;i++){
        if(!tempTree[item[i]])
            tempTree[item[i]] = {};
        tempTree = tempTree[item[i]];
    }
    return tree;
}, {});