How to check if layer with specific name exists?


How to check in UXP if layer with specific name exists?


If layer exists do something, if not, do something else.

Thank You!

A bit modified answer of this topic

import {app} from "photoshop"

const layerExistsByName = (name) => {
  return Boolean(app.activeDocument?.layers?.some(layer => === name))

const exists = layerExistsByName("Some layer name")
console.log(exists) // true | false

Thank You so much! That’s super smart. I’ll test this shortly and I’ll let you know how it works.


note: for thousands of layers this can be magnitude slower than necessary. You can use batchPlay with name in reference to getting the fastest performance. If you need performance.

1 Like

Hi Karmalakas,

It works perfectly, thank you so much! the only change I had to make was:

const layerExistsByName = (name) => {


1 Like

Oh, mistype :slight_smile: Fixed :wink: