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

124
Vistas
Using maps over template literals

so I need to print a boolean value if the given string contains [[placeholder:var3]] but the var3 will be dynamically fed from an array as belwo:

const delmethod = ['all', 'email', 'sms', 'fax', 'voice', 'voicemail', 'pager', 'pagerTwoWay'];
let languages = organizationLocales.map(a => a.locale);
 let variabless = alertDetails.variables?.map(k => k.name); languages && languages.length > 0 && languages.map(lang => { delmethod.map(i => {
 if ( alertDetails.alertMessage?.[${lang}]?.[i]?.variabless?.some(el => [i] === [[placeholder:${el}]]) ) 
{ bodyContainsVariables = true; } }); })

I tried using map around the template literals but it is throwing me an error also tried like above eg but it checks only first value of the array, so can someone please help me solve this, I'd appreciate any help, thanks in advance.

updating the question with the actual PS. organizationLocales is an array and alertDetails is an object that has an variables array, Delmethod is an array is being used to check the different properties dynamically

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

0

You need to tell the index inside template literals becasue variabless is an array like this:

console.log(s.includes(`[[placeholder:${variabless[2]}]]`));

I hope it helps you.

about 4 years ago · Juan Pablo Isaza Denunciar

0

you're currently passing the whole array in

s.includes([[placeholder:${variabless}]])

and that's won't work, you need to specify which elemnt of the variables array you want to inject to your string which is element indexed with 2 so it should be like that

s.includes([[placeholder:${variabless[2]}]])

about 4 years ago · Juan Pablo Isaza Denunciar

0

[[placeholder:${variabless}]] yields [[placeholder:var1,var2,var3]]. It doesn't check the first variable. And that's not how Array.string.includes is supposed to be used. For checking exact match use the === operator.

In case you want to check if any of the array elements match the string you can use the Array.prototype.some method which returns a boolean value.

let any = variabless.some(el => s === `[[placeholder:${el}]]`)

If you want to find the element that matches with the string use the Array.prototype.find function.

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