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

205
Views
Express: cannot access an array of numbers even though it is in the request body

Express / Typescript:


export const updateSettings = catchErrors(async (req, res) => {

  console.log("updateSettings req.body: ", req.body)
  
  const { organizationId, formdata, updatedItems, updateQuota } = req.body; 

  console.log("organizationId: ", organizationId);
  console.log("formdata: ", formdata);
  console.log("updatedItems: ", updatedItems);
  console.log("updateQuota: ", updateQuota);
  console.log("req.body.updateQuota: ", req.body.updateQuota);

  res.respond({'message': 'Settings updated successfully!' })

}); 

the console log for req.body is as follows:

updateSettings req.body:  {
  username: 'staff_a',
  organizationId: '2',
  formData: '{"offDays":[0,6,1],"officeHourStart":"1899-12-31T09:00:00.000+09:00","officeHourEnd":"1899-12-31T18:00:00.000+09:00","displayLanguage":"cn","timezone":"beijing","doctorQuotas":{"5":5,"6":10}}',
  updatedItems: [ 'displayLanguage', 'timezone', 'billingClosingDay', 'offDays' ],
  updatedQuota: [ 6, 5 ]
}

As you can see, there are fields updatedQuota and updatedItems. One is an array of strings and the other is an array of numbers;

However, after the destructoring line const { organizationId, formdata, updatedItems, updateQuota } = req.body; , some of fields are fine, but some fields becomes undefined:

organizationId:  2
formdata:  undefined
updatedItems:  [ 'displayLanguage', 'timezone', 'billingClosingDay', 'offDays' ]
updateQuota:  undefined

if I access the req.body.updateQuota alone by printing it console.log("req.body.updateQuota: ", req.body.updateQuota);, it is also empty:

req.body.updateQuota:  undefined

Why is it that things are clearly contained in req.body, but cannot be accessed or extracted?

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

0

formData or formdata ?

updatedQuota or updateQuota ?

about 4 years ago · Juan Pablo Isaza Report

0

req.body has updatedQuota not "updateQuota"

about 4 years ago · Juan Pablo Isaza Report

0

{username, organizationId, formData, updatedItems, updateQuota} = req.body
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!