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

164
Views
a shorter way to change some object values to uppercase

I have a large object and need to change some values (not all of them) to upperCase

obj.state = obj.state.toUpperCase();
obj.city = obj.city.toUpperCase();
obj.street = obj.street.toUpperCase();
obj.title = obj.title.toUpperCase();

is there a shorter way, like this:

obj(state,city,street,title).toUpperCase();  

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can iterate through all the keys of the object and do something like this:

for (const k of Object.keys(obj)) {
  obj[k] = obj[k].toUpperCase()
}

If you only want to update some of the values, you can filter the keys:

const keys = ['state', 'city', 'street', 'title']
for (const k of Object.keys(obj).filter((k) => keys.includes(k))) {
  obj[k] = obj[k].toUpperCase()
}

You can turn it into a function to make it reusable:

function objToUpperCase(obj, keys) {
  for (const k of Object.keys(obj).filter((k) => keys.includes(k))) {
    obj[k] = obj[k].toUpperCase()
  }
  return obj
}
// to call:
objToUpperCase(obj, ['state', 'city', 'street', 'title'])
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!