Recursive material name printing logic
You could call itemList recursively for each object in x.materials:

var itemList = function(x) {
    for (var i = 0; i &lt; x.materials.length; i++) {
        console.log(x.materials[i].name);
        if (x.materials[i].build !== "BasicFactory" &amp;&amp; i !==0) {
            itemList(x.materials[i]);
        }
    }
};