Home > Mobile >  mapping objects inside another mapping react native
mapping objects inside another mapping react native

Time:10-15

i am trying to map an object that is inside another object and i have tried to use this code inside a scrollview:

{Object.entries(exceptions).map(([key, value]) => {
    Object.entries(value).map(([num, photo]) => {
      let Qnum = num;
      let qType = key;
      let image = photo;
      return (
            <CustomCard
              questionNumber={Qnum}
              questionType={qType}
              image={image}
              key={`${key}, ${value}, ${photo}`}
            />
      );
    });
  })}

the object looks like this:

{"Qtype":{"key":val},"another":{"key":val}}

this doesn't return the card i want

CodePudding user response:

You are just mapping in the 2D array. Just add an return statement before second loop or else just remove your {} brackets

{Object.entries(exceptions).map(([key, value]) =>
    Object.entries(value).map(([num, photo]) => {
      let Qnum = num;
      let qType = key;
      let image = photo;
      return (
            <CustomCard
              questionNumber={Qnum}
              questionType={qType}
              image={image}
              key={`${key}, ${value}, ${photo}`}
            />
      );
    });
  })
  • Related