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

274
Views
Map database params field values to custom names

I am trying to handle an array of errors on the front end side and display them on the page. I am getting the fields that user has entered from the backend and trying to map them out. However, backend params are being returned in camelcase. Please see below:

enter image description here

I want to render: The input field(s) for email, favorite sport, gpa score are unacceptable

But I am seeing

The input field(s) for email, favoriteSport, gpaScore are unacceptable

Is there any way I can map the name of the params to a custom name?

Here is my code:

Array.isArray(errors) ? `The input fields for ${errors.map(item => item.param)} are unacceptable`

Any way i could map the param names to my own liking?

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

0

const mapper = (item) => {
  return {
   gpaScore: 'GPA Score',
   favoriteSport: 'Favorite Sport',
  }[item.param] || 'Unknown property'
} 

return `The input fields for ${errors.map(item => mapper(item)).join(', ')} are unacceptable`
about 4 years ago · Juan Pablo Isaza Report

0

This is where you could use something like react-intl to format messages but in general, you'd need something that turns programmatic keys into user-friendly messages

const t = {
  email: "email",
  favoriteSport: "favourite sport",
  gpaScore: "GPA score"
}

const fields = errors.map(({ param }) => t[param] ?? param)

const message = `The input fields for ${fields.join(", ")} are unacceptable`
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!