I have a JSON to parse. I'm trying to use recursive method here.The current JSON has a structure similar to the bottom one
Item 01
SubItem 01
InnerSubItem 01
Item 02
SubItem 01
InnerSubItem 01
Using the function I created, I'm able to parse only the first set (Contents under Item 01). The code doesn't comes back to the loop when is condition is false
Code used
$.getJSON('https://api.myjson.com/bins/6atbz', function(data) {
repeat(data, data.layers);
})
function repeat(data, x) {
var layer = data.layers.reverse()
for (i = 0; i < x.length; i++) {
name = x[i].name
console.log(name)
if (x[i].layers.length > 0) {
repeat(data, x[i].layers)
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>