Data:
var data = [ { \"id\": 1, \"level\": \"1\", \"text\": \"Sammy\", \"type\": \"Item\", \"items\": [
With a bit of ES6 flavor
function flatten(xs) { return xs.reduce((acc, x) => { acc = acc.concat(x); if (x.items) { acc = acc.concat(flatten(x.items)); x.items = []; } return acc; }, []); }