PSD LOOP LAYERS

by João Vitor Scheuermann

JavaScript

let teste = [ 
	{name:"{export:true}", type:"group", childrens: [
  	{name:"child01a", type:"layer", childrens: []},
    {name:"child01b", type:"group", childrens: [
    	{name: "child01b-01", type:"layer", childrens: []}
    ]}
  ]},
  {name: "other layer", childrens:[]}
];

function loopChilds (array) {
		array.forEach(child => {    		
    
    		if (child.childrens.length > 0 && child.type === "group") {
        		loopChilds(child.childrens);
        } else if (child.type === "layer") {
        		console.log(child.name)
        }
        
    })		
}

function loopParents (array) {
		array.forEach(el => {
    
    		if (el.name === "{export:true}" && el.type === "group") {
        
        		if(el.childrens.length > 0) {
            		loopChilds(el.childrens)
            }
        }        
    })	
}

loopParents(teste);