Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

329
Vistas
Photoshop scripting (.jsx): push string into an Array only if it doesn't exist there yet

I have a unique signature being generated for each iteration, which I want to eventually save on a .txt file.

My signature is quite simple, using 0-9 and A-Z, being 14 chars long.

I want to push it to an Array only if that Array doesn't contain it yet. Here is what I tried to do:

var uniqueSignature = []

do {
    var uniqueSignature = generateSignature()
    if (!signatureArray.includes(uniqueSignature)){ //checks if the Array does not contain the signature.
        signatureArray.push(uniqueSignature) //pushes the signature into the array.
    }
} while (!signatureArray.includes(uniqueSignature)) //Keep doing so until the signature can be inserted (meaning is unique)

function generateSignature(){
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    var signatureLength = 14
    var genSignature = ""
    for (var i = 0; i <= signatureLength; i++) {
        var randomChars = Math.floor(Math.random() * chars.length)
        genSignature += chars.substring(randomChars, randomChars +1)
    }
    currentSignature = genSignature 
}

//[... eventually will write the array to a .txt files]

When I try to run it on Adobe Photoshop > Browse > Load script, I get this error: enter image description here

I've also tried to replace .includes for .indexOf, pushing it only if signatureArray.indexOf(uniqueSignature) == -1, but got the same error.

Any ideas? I know that jsx/Photoshop has some limitations when it comes to code (like it won't let me use ${var} and such). Is that the thing here?

If so, is there any other way for me to achieve this push after verification?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've managed to bypass this by working with a String instead of an Array:

var currentSignature
var z = 0

do {
    generateSignature()
    
    if (signatureString.indexOf(currentSignature) == -1){
        signatureString = signatureString + currentSignature + '\n'
        z = 1
    }
} while (z = 0)

In the future, I can pass a .join('\n') if I need to convert the string (file content) into an Array again.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda