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

93
Vistas
Reactjs error reading a Javascript Object Notation

I have 2 codes.

1.this giving error:

import userdata from "./data.json";
userdata = userdata.userdata;
userdata.map() // do map here.

that giving error: Uncaught TypeError: Cannot read properties of undefined (reading 'userdata')

  1. this works:
import userdata from "./data.json";
userdata.userdata.map() // do map here.

json: {"userdata":[{name, job}, {name, job}]}

why the second code is working?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In the first example you import userdata and then try to assign it the value of userdata.userdata.

This isn't possible as you can't assign a new value to an import.

Therefore when you try map over userdata it is still trying to map over userdata from the initial import (and not userdata.userdata).

If you want this to work rather use a new variable name like below:

import userdata from "./data.json";

const userDataArray=userdata.userdata;
userDataArray.map()

In the second example, you reference the array correctly (with userdata.userdata), instead of trying to assign a value to the import.

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