0

I have an array here that I would like to map out and list in radio check boxes.

I currently can only get one item of the array to return by typing out for example: <IonLabel>{item[1]}</IonLabel>

How would I get all of them to list out?

'equipment' Array

{0: "Camera", 1: "Wide Angle Lens (16mm equivalent)", 2: "Tripod", 3: "Drone"}

0: "Camera"
1: "Wide Angle Lens (16mm equivalent)"
2: "Tripod"
3: "Drone"

Current Code

{equipment.map((item, i) => {
          return (
        <IonItem key={i}>
         <IonLabel>{item}</IonLabel>
         <IonRadio slot="start" value="biff"/>
        </IonItem>

          );
        })}

2 Answers 2

2

Looks like you are using not an Array, but an Object with numbers as keys.

Try this one:

{
  Object.values(equipment).map((item, i) => (
     <IonItem key={i}>
       <IonLabel>{item}</IonLabel>
       <IonRadio slot="start" value="biff"/>
     </IonItem>
   )
  );
}

Another solution could be in rewriting your equipment to look like:

const equipment = ["Camera", "Wide Angle Lens (16mm equivalent)", "Tripod", "Drone"] In this case, you could use your previous implementation.

Sign up to request clarification or add additional context in comments.

Comments

0

What you have here is not an array, but an object.

You can store the data in an array like this:

['Camera', 'Wide Angle Lens (16mm equivalent)', 'Tripod', 'Drone']

Now you can iterate over it using map just like you have done in your example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.