How-to return boolean from array
In this script that moves layers with the same name I would like to include layers that are locked and hidden while maintaining their state once transferred. I am failing at retrieving the push value and using it as a boolean.
/--------------------------------------------------
// MergeLayers
//--------------------------------------------------
function MergeLayers() {
if (!documents.length) return;
var doc = app.activeDocument;
var layerGroups = collectSameLayers(doc);
moveLayersToNew(doc, layerGroups);
}
// Collect layers with the same name
function collectSameLayers(doc) {
var layerGroups = [];
for (var i = 0; i < doc.layers.length; i++) {
var currLayer = doc.layers[i];
var currName = currLayer.name;
var isFound = false;
var isLocked = false;
var isVisible = true;
if (currLayer.locked === true) {
isLocked = [true];
currLayer.locked = false;
}
if (currLayer.visible === false) {
isVisible = [false];
currLayer.visible = true;
}
for (var j = 0; j < layerGroups.length; j++) {
if (layerGroups[j].name === currName) {
layerGroups[j].layers.push(currLayer);
isFound = true;
break;
}
}
if (!isFound) {
layerGroups.push({name: currName,layers: [currLayer],lockStatus: [isLocked],visibleStatus: [isVisible]});
}
}
return layerGroups;
}
// Create new layer and move inside original layers
function moveLayersToNew(doc, layerGroups) {
for (var i = layerGroups.length - 1; i >= 0; i--) {
var currGroup = layerGroups[i];
; // Only process if there are multiple layers with the same name
if (currGroup.layers.length > 1) {
var newLayer = doc.layers.add();
newLayer.name = currGroup.name;
for (var j = currGroup.layers.length - 1; j >= 0; j--) {
currGroup.layers[j].move(newLayer, ElementPlacement.INSIDE);
// need help using the lockStatus and visibleStatus boolean from the layerGroups array
currGroup.layers[j].locked =
currGroup.layers[j].visible =
}
}
}
}
