I have the following array:

```
var sampleArray = [
  "CONTAINER",
  "BODY",
  "NEWS",
  "TITLE"];

```

I want to have the following output:

```
var desiredOutput = [{
        "CONTAINER": [{
            "BODY": [{
                "NEWS": [{
                    "TITLE": []
                }]
            }]
        }]
    }];

```

How can I achieve this in JavaScript?

Already tried with recursive loop, but it does not work, gives me undefined.

```
    dataChange(sampleArray);
    function dataChange(data) {
        for (var i = 0; i < data.length; i++) {
            changeTheArray[data[i]] = data[i + 1];
            data.splice(i, 1);
            dataChange(changeTheArray[data[i]]);
        }
    }

```

Thanks