Is it possible to iterate over all layers to get their layerID property?

I’m trying to iterate over all layers in the document to get the “layerID” property for each layer.

This is easy for the “name” property using

const photoshop = window.require("photoshop").app;
const activeDocument = await photoshop.activeDocument;
const layers = await activeDocument.layers;

for (i = 0; i < layers.length; i++){
let layerName = await layers[i].name;
console.log(layerName)
}

But is there way to do this for the “layerID” property instead of the “name” property? I don’t see a way to do it with an API, and batchPlay doesn’t accept “layers[i]” as a reference.

Try
let layer_id = await layers[i]._id;

Alternatively, you can use:

  const allLayer_ID = layers.map(layer => layer._id);
  console.log("allLayer_ID", allLayer_ID)

Now allLayer_ID is an array with PS stack layer IDs from top to bottom.

Yeah, that’s it. Thank you. I tried:

layers[i].id
layers[i].ID
layers[i].layerID
layers[i].layerId

and probably about a half dozen more.

Is this documented somewhere? I couldn’t find the documentation on layers[i].name either, but had used it successfully previously, so figured there must be and “id” option too.

Yep. Using the DevTools Console, you can spot some props: