Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get a specific values in an Array to variables in React

I have an Array and I would like to acquire the following data into variables. How this can be done. I’m really new to React and would like to know how to do this too.

My Array

array in console

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want to get the following information and My array’s name is EventInformation

const movieId = 0
const movieDate = 0
const showtimeId = 0
const venueId = 0

>Solution :

First of all the main thing in the screenshot is an object, not an array. The name of the object isn’t given either, but you should know since you printed it to console. I’ll just use myObj for the name.

Const movieId = myObj.movieId;
Const movieDate = myObj.venueInfo[0].date;
Const showtimeId = myObj.venueInfo[0].venues[0].showtimes[0].showtimeId;
Const venueId = myObj.venueInfo[0].venues[0].venueId;

This is hard-coded to only get the value of the first venu. The venues were made into an array for a reason so I would suggest making a loop through all the venues if there is more than one venu you want.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading