Your LayerNames array contains the Layer objects and not the names Vasily 😋
But adding to this, ILST can have nested layers so if your use case is needing all layers and sublayers within no matter the depth, you'll need to collect them recursively:
function get(type, parent, deep) {
if (arguments.length == 1 || !parent)
(parent = app.activeDocument, deep = true);
var result = [];
if (!parent[type]) return [];
for (var i = 0; i < parent[type].length; i++) {
result.push(parent[type][i]);
if (parent[type][i][type] && deep)
result = [].concat(result, get(type, parent[type][i], deep));
}
return result || [];
}
var list = get("layers"); // Returns all layers and sublayers no matter their depth
// If Layer 1 (1 depth) contains Layer 2 (2 depth) which contains Layer 3 (3 depth)
for (var i = 0; i < list.length; i++) {
alert(list[i].name) // Returns Layer 1, Layer 2, Layer 3
}
This returns as a flat array, e.g. [Layer 1, Layer 2, Layer 3] and not nested: [ { name: "Layer 1", layer: Array} ]. If you need to convert the above to only names and not Layer objects
Array.prototype.map = function (callback) {
var mappedParam = [];
for (var i = 0; i < this.length; i++)
mappedParam.push(callback(this[i], i, this));
return mappedParam;
};
var layerNames = list.map(function (layer) {
return layer.name;
})