Thx for your attention, Andrei!
I figured out why this formula didn’t work.
I tried to figure out this problem for a long time, went through many options, nothing worked, but it gave me a basic understanding of the patterns, and it turned out that the author posted this code simply with syntax errors (apparently, some text editor messed up the text).
Here is a working formula (I added a little to it so as not to mention the name several times.
var proj = app.project;
var itms = proj.items;
var itmsLen = itms.length;
var curItem = myComp;
var layerName = "/YOUR LAYER NAME/";
for(var i=0; i<itmsLen; i++){
curItem = itms;
if(curItem instanceof CompItem){
if(curItem.name == layerName ){ //Will grab only the first name match
myComp = curItem;
break;
}
}
}
var chkLayer = myComp.layer(layerName );
if (chkLayer == undefined){
//do something
}else{
//do something else
}