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

243
Views
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 answers
Answer question

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 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!