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

244
Vistas
React cannot access multidimensional array state value

In my react application I am setting the state value as an array using the below code.

const [ds_data, setDsData] = useState([]);
    let ds_arr = res.data.map((elem, index) => {
                  return elem.split(" ")
                })
                setDsData(ds_arr)

The values in the array when I use console.log(ds_arr) are

enter image description here

The value I am getting from the server is given below. enter image description here

The problem is when I try to display the value of the multidimensional array using {ds_data[0][0]}, I am getting the error:

Uncaught TypeError: Cannot read properties of undefined (reading '0')

in the console. When I used {ds_data[0]} it is showing all the array values as a single string:

363861319e9d5720089762a51d24a86dd1402dbba64771c9

The data is displayed inside a bootstrap modal component

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

0

The problem was that the state was not set initially, so I have to check if the state was set using the code {Array.isArray(ds_data) && Array.isArray(ds_data[0]) ? ds_data[0][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