Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda