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

144
Vistas
Mapping through an Array with .map() but excluding 1 item

I have an array:

let people = ['lucy', 'jerry', 'ricky', 'jessy', 'jerry', 'phil']

And I want to capitalize every word except jerry. How would I go about this?

I know how to map through the array:

let output = people.map(person => { 
      return person.toUpperCase()
}
console.log(output)

Obviously, that returns the entire array with every word capitalized. But again, what if I wanted to capitalize all of the words in the array except jerry, which is written twice?

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

0

Here is a quick and scalable method. Set the exclusions in their own array and just check for them in the map loop.

let people = ['lucy', 'jerry', 'ricky', 'jessy', 'jerry', 'phil']
let exclude=['jerry'];

let output = people.map(person => exclude.includes(person) ? person : person.toUpperCase())
console.log(output)


let output2 = people.map(person => exclude.includes(person) ? person : person[0].toUpperCase() + person.slice(1))
console.log(output2)

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