Sort array of objects with hierarchy by hierarchy and name
Since you have a representation of a tree i suggest using it,
then traverse it in pre-order 

So if 

[
    {_id:1, parent:0, name:'Z'},
    {_id:4, parent:0, name:'A'},
    {_id:2, parent:1, name:'H'},    
    {_id:8, parent:2, name:'G'},        
    {_id:5, parent:4, name:'M'},
    {_id:6, parent:4, name:'N'},
    {_id:3, parent:1, name:'Z'},
    {_id:7, parent:2, name:'L'}
]


lets build a tree like this

   [
      {_id:1, parent:0, name:'Z', children: 
         [
             {_id:2, parent:1, name:'H', children: 
                [
                   {_id:8, parent:2, name:'G', children: []},
                   {_id:7, parent:2, name:'L', children: []}
                ]
             },
             {_id:3, parent:1, name:'Z', children: []}
         ]
      },
      {_id:4, parent:0, name:'A', children: 
         [
             {_id:5, parent:4, name:'M', children: []},
             {_id:6, parent:4, name:'N', children: []}
         ]},
   ]


my suggestion is like this:

var nodes = [
    {_id:1, parent:0, name:'Z'},
    {_id:4, parent:0, name:'A'},
    {_id:2, parent:1, name:'H'},    
    {_id:8, parent:2, name:'G'},        
    {_id:5, parent:4, name:'M'},
    {_id:6, parent:4, name:'N'},
    {_id:3, parent:1, name:'Z'},
    {_id:7, parent:2, name:'L'}
]
var tree = {_id:0};



var addChildrenToNode = function(node,cmp){
    var currentNodeId = node._id;
    node.children = [];
    nodes.forEach(function(e){
        if(e.parent === currentNodeId){
            e = addChildrenToNode(e);
            node.children.push(e);
        }
    });
    node.children = node.children.sort(cmp); // sort the children
    return node;
};

var cmp = function(a, b) { 
    if(a.name &lt; b.name) return -1; 
    if(a.name &gt; b.name) return 1; 
    return 0; 
};
tree = addChildrenToNode(tree,cmp);


Then you only have to do the pre-order traverse, like this:

var preOrderTraverse = function(node, fn){ // sends values of tree to fn in pre-order
    fn(node); //call at preorder
    if(node.children.length &gt; 0){
        node.children.forEach(function(e){
            preOrderTraverse(e,fn);
        });
    }
}

preOrderTraverse(tree,
    function(node){ // do what you like with each node
        console.log(node);
    }
);