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

227
Views
TypeError: Cannot convert undefined or null to object: point me in the right direction

I've found many issues and solutions to this online but I'm kinda new and tbh I couldn't make it work. It's probably pretty silly but yeah, I need help :)

  • The error:
TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)
    at organizeCategoryData (C:\Users\alan_\Desktop\melonwallet\utils\records.js:59:35)
    at getRecords (C:\Users\alan_\Desktop\melonwallet\controllers\recordController.js:125:30)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  • C:\Users\alan_\Desktop\melonwallet\utils\records.js:59:35
organizeCategoryData(categoryList, amountByCategory) {
    const categoryObject = Object.assign(    /// LINE 59
      ...categoryList.map(category => ({
        [category.name]: amountByCategory[category._id] || 0
      }))
    )
    categoryList.forEach(category => {
      category.amount = categoryObject[category.name]
    })
    return categoryObject
  }
  • (C:\Users\alan_\Desktop\ironhack\melonwallet\controllers\recordController.js:125:30)
const categoryObject = organizeCategoryData(   //// LINE 125
        categoryList,
        amountByCategory
      )

Thank you so much!

/edit: forgot to clarify this only happens when I try to log-in with a previously created user.

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

0

organizeCategoryData(categoryList, amountByCategory) {
const cList = categoryList || []; //This will add a check for null and undefined
const categoryObject = Object.assign(    /// LINE 59
  ...cList.map(category => ({
    [category.name]: amountByCategory[category._id] || 0
  }))
)
cList.forEach(category => {
  category.amount = categoryObject[category.name]
})
return categoryObject

}

about 4 years ago · Juan Pablo Isaza Report

0

Object.assign only works with objects. ...categoryList.map(...) is an array. Either put Object.assign within the map (or forEach, since it doesn't return anything). Or take a look at Object.fromEntries.

const categoryObject = {};
categoryList.forEach(category => 
  Object.assign(categoryObject, {
    [category.name]: amountByCategory[category._id] || 0
  })
);

// or 

const categoryObject = Object.fromEntries(
  categoryList.map(cat => ([cat.name, amountByCategory[cat._id] || 0]))
);

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!