Returning existing layers and layers.length with UXP for Photoshop

Hi,

What’s the correct way to return an array of the existing layers and the length of that array with UXP for Photoshop?

I’m having trouble understanding the result when I access: require(“photoshop”).app.activeDocument.layers.length

Here’s some test code:

async function test_modal_function(){
console.log(“test_modal_function”)
console.log(require(“photoshop”).app.activeDocument.layers.length)
console.log(“end test_modal_function”)

}

async function runModalFunction_test_modal_function() {
await executeAsModal(test_modal_function, {“commandName”: “test_modal_function”});
}

Here’s the log:
runModalFunction_test_modal_function()
Promise {}
test_modal_function
layers.length 1
end test_modal_function

Here’s a screenshot of the layers panel:

What am I doing wrong?

Thanks!

If you’ve searched the forum, you would’ve found this topic:

If you read through the topic, you’d find some links and quotes from the docs, that .layers returns only top level layers (in your case it’s only one group layer)

Thanks. This clarified what I couldn’t figure out from the docs.