Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda