Q:

Determine which level i'm in the JSON tree

I may have a simple problem, but i can't figure it out. If I have a multy denominational JSON array like so:
[
    {
        "name":"one",
        "children":
        [
            {
                "name":"two",
                "children":
                [
                    {
                        "name":"two",
                        "children": []
                    }, 
                    ... 
                ]

            },
            ...
        ]

    }
]

I want to determine what level i'm at. If I was going to loop true all the first entities what will be printed is bellow: 
one -|
     two -> View Children

Once "View Children" will be clicked:
one -|
     two -| 
          three -> View Children || Go Back.

And if "Go Back" is clicked we go back to:
one -|
     two -> View Children

So It's similar to a Hierarchy. I can't figure out how to make the back button work. I was able to figure out the go forward using this peace of code:
level = obj; // OBJ is the json data.

function inside(events){
    temp = "";
    for (i in events) {
      temp += "<li id='"+events[i].id+"' class='"+events[i].type+"' index='"+i+"''>&nbsp;&nbsp;"+events[i].name+ "</li>";
    }
    return temp;
}

text += inside(obj);

$('#filebrowser').on('click','li.folder',function(e){

    var index =  $(this).attr('index');
    var html = "<li class='folder back' index='"+index+"'>back</li>";

    if(level[index].children){
        html = html + inside(level.[index].children);
        level = level[index].children;
    } 

    $('#filebrowser').html(html);
    e.stopPropagation();

});

I just wanted to say this is can be dynamic, many go back's should occur, so storing the back obj in a variable is not going to cut it.

A:

Generally stacks are used to keep track of things like navigation history. Most programming languages include implementations of some sort of a stack structure. In Javascript stack functionality is built into the Array structure. Check out the push() and pop() methods. 
As you navigate forward you can push() the last page onto the history stack. As the back button is pressed you can pop() entries off in the same order they were added, until you reach the first entry.
It might look something like this:
var backStack = [];
$('#filebrowser').on('click','li.folder',function(e){

    var index =  $(this).attr('index');
    var html = "<li class='folder back' index='"+index+"'>back</li>";

    if(level[index].children){
        html = html + inside(level.[index].children);
        level = level[index].children;
    } 

    backStack.push($('#filebrowser').html);
    $('#filebrowser').html(html);
    e.stopPropagation();

});

Then on back button pressed:
$('#filebrowser').html(backStack.pop());

Or something along those lines. 

