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

177
Vistas
Can i use internationalisation api to format sentence to have "and" word before last item?

I am trying to create a string with where i want to have the following

  1. there should be and word before the last word in the sentence
  2. if there is just one word then no and.

for and array ['john','harry', 'darren']

i expect below

e.g john harry and daren

is it even a valid case for internationalisation or am i better off just programming do this?

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

0

You may create a function, and the body will look something like this:


function myFunc (a) {
    if (a.length > 1) {
        const exceptLast = a.slice(0, -1)
        let last = a.slice(-1)
        last = ['and', ...last]
        return [...exceptLast, ...last].join(" ")
    }
    return a[0]
}

Test it like this:


const da = ['b', 'cc', 'ddd']
const da1 = ['b']
const da2 = ['b']



console.log(myFunc(da))
console.log(myFunc(da1))
console.log(myFunc(da2))
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