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

103
Views
How Can I save a javascript map object to database

I am able to get my map object as

Map(3) {'2a820899-844f-4fe1-bec6-e4c348920485' => 'Yes', 'c30102dc-ffe8-4a3f-9498-59625d9981c4' => 'Me is me', '5b44fe6a-2453-43f9-bf1b-3c3adc51cc96' => 'Yes'}

when I log it to the console. but when I send it to the backend, I get an empty object. How do i fix this?

const [answers, setAnswers] = useState(new Map())

  function updateAnswer(id, value) {
    const newMap = new Map(answers)
    newMap.set(id, value)
    setAnswers(newMap)
  }

const handleSubmit = async (e) => {
    e.preventDefault()
    console.log(answers)
    await createAnswers(name, phone, email, city, answers)
  }

on the console, I get the above data. But when I save it, I gt an empty object

export const createAnswers = (name, phone, email, city, answers) => {
  return request('/v1/answers', {
    data: {
      name,
      phone,
      email,
      city,
      answers,
    },

    method: 'POST',
  })
}
about 4 years ago · Santiago Trujillo
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!