Help Me Understand The Dom

I am starting to look closely at API 2 but need to help to get me started.

How To Duplicate A Layer:
Looking at the docs, the following example code is supplied to duplicate a layer but simply copying and pasting doest work for me.

Can someone show me an example on how to use the following example code.

// duplicate a layer
const copyLayer = await layer.duplicate()

// extract to a new document
const exportDoc = psApp.documents[1]
const exportedLayer = await layer.duplicate(exportDoc)

How are you using it? This snippet alone won’t work. What is layer in your case?

I just copied and pasted the code direct from the docs.
What is the best way to ref the layer

Where did you paste it? You should get a layer first. Eg.:

import {app} from "photoshop"

const layer = app.activeDocument.activeLayers[0]
const copyLayer = await layer.duplicate()

Thank You, that worked great