Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!