1

I have an Array of Objects, and those objects have an object with an array in it. I want to map the "shoot: Array(6)" so I can list out the items.

How would I go about this? Im able to map the name, id, and instructions, but im having trouble getting access to and mapping the shots object then shoot array.

Current Code Information:

{Object.values(instructions).map(({id, name, Instructions}, i) => {
          return (
        <div key={id}>
         <p><b>{name}</b></p>
         <p>{Instructions}</p>
        </div>

          );
        })}

3 Answers 3

1

You can map on the shoots array within each object like this:

{Object.values(instructions).map(({id, name, Instructions}, i) => {
      return (
    <div key={id}>
     <p><b>{name}</b></p>
     <p>{Instructions}</p>
    {shoot.shoots.map(shoot => (<p>{shoot}</p>))}

    </div>

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

Comments

0

try this code:

{Object.values(instructions).map(({id, name, instructions, shots}, i) => {
      return (
    <div key={id}>
     <p><b>{name}</b></p>
     <p>{instructions}</p>
     <p>{shots.amount}</p>
     {shots.shoot.map(item => (
       <div>{item}</div>
     ))}
    </div>
      );
    })}

Comments

0

Destruct the Shots object along with {id, name, Instructions} and map the shoots array from the Shots object.

{
  Object.values(instructions).map(({id, name, Instructions, Shots}, i) => {
      return (
        <div key={id}>
          <p><b>{name}</b></p>
          <p>{Instructions}</p>
          {
            Shots.shoots.map(shoot => (<p>{shoot}</p>))
          }
        </div>
      );
  })
}

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.