JavaScript How to traverse key-value in reactjs

I'm trying to efficiently make a key-value tour in an array in reactjs.

However, I do not know how to display the "key" array without creating another map function.

const equipos = [
  {
    key: [
      'Real Madrid',
      'Manchester United',
      'Champions League',
      'English Premier League',
      'Bayern Munchen',
      'Juventus',
      'Arsenal',
    ],
    images: [
      'http://as00.epimg.net/img/comunes/fotos/fichas/equipos/large/1.png',
      'https://4.bp.blogspot.com/_Z_YWTFNHUvw/TQDBKNXdwcI/AAAAAAAACI0/COhwIG2PkFA/s320/Manchester-United%255B1%255D.png',
      'http://www.stickpng.com/assets/images/5842fe06a6515b1e0ad75b3b.png',
      'https://i.pinimg.com/originals/f1/44/fc/f144fc61d0b0ed7716d740aa9deefb07.png',
      'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/FC_Bayern_M%C3%BCnchen_logo_%282017%29.svg/1200px-FC_Bayern_M%C3%BCnchen_logo_%282017%29.svg.png',
      'http://as00.epimg.net/img/comunes/fotos/fichas/equipos/large/29.png',
      'https://i.pinimg.com/originals/98/32/8b/98328b1d64c5f93ef5eceea7586430d1.png',
    ],
  },
];

console.log(equipos.images)

const IconosSeccion = () => (
  <div className="containerIconosSeccion">
    <div className="parentIconos" />
    {equipos.map(equipo => (
      <div>
        {equipo.images.map(image => (
          <div className="backgroundIconoIndependiente">
            <img alt="#" className="iconoIndependiente" src={image} />

            <span className="textoIconoIndependiente">Real madrid</span>
          </div>
        ))}
      </div>
    ))}
  </div>
);

I want to show it in the span of the classname textIconoIndependiente.

Thank you!

Answer:1

The second argument passed to the map function is the index, which you could use to read the correct key.

const IconosSeccion = () => (
  <div className="containerIconosSeccion">
    <div className="parentIconos" />
    {equipos.map(equipo => (
      <div>
        {equipo.images.map((image, index) => (
          <div className="backgroundIconoIndependiente">
            <img alt="#" className="iconoIndependiente" src={image} />
            <span className="textoIconoIndependiente">{equipo.key[index]}</span>
          </div>
        ))}
      </div>
    ))}
  </div>
);
Answer:2

I'm not sure your data is well formatted.

I suggest you another format. In that way, It's possible to render your image and the name of the club with only one map.

const equipos = [
      {name:'Real Madrid',image:'http://as00.epimg.net/img/comunes/fotos/fichas/equipos/large/1.png',},
      {name:'Manchester United',image:'https://4.bp.blogspot.com/_Z_YWTFNHUvw/TQDBKNXdwcI/AAAAAAAACI0/COhwIG2PkFA/s320/Manchester-United%255B1%255D.png',},
      {name:'Champions League',image:'http://www.stickpng.com/assets/images/5842fe06a6515b1e0ad75b3b.png',},
      {name:'English Premier League',image:'https://i.pinimg.com/originals/f1/44/fc/f144fc61d0b0ed7716d740aa9deefb07.png',},
      {name:'Bayern Munchen',image:'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/FC_Bayern_M%C3%BCnchen_logo_%282017%29.svg/1200px-FC_Bayern_M%C3%BCnchen_logo_%282017%29.svg.png',},
      {name:'Juventus',image:'http://as00.epimg.net/img/comunes/fotos/fichas/equipos/large/29.png',},
      {name:'Arsenal',image:'https://i.pinimg.com/originals/98/32/8b/98328b1d64c5f93ef5eceea7586430d1.png'}
];

const IconosSeccion = () => (
  <div className="containerIconosSeccion">
    <div className="parentIconos" />
    {equipos.map(equipo => (
      <div>
          <div className="backgroundIconoIndependiente">
            <img alt="#" className="iconoIndependiente" src={equipo.image} />

            <span className="textoIconoIndependiente">{equipo.name}</span>
          </div>
      </div>
    ))}
  </div>
);
Answer:3

Here is the code: function fil(val) { console.log('fil'); // never written to console when run in greasemonkey return true; } var temp = unsafeWindow.someobject; console.log(temp); // looks fine ...

Here is the code: function fil(val) { console.log('fil'); // never written to console when run in greasemonkey return true; } var temp = unsafeWindow.someobject; console.log(temp); // looks fine ...

  1. what could stop you from getting a passport
  2. what could stop you from getting pregnant
  3. what could stop the ocean currents
  4. what could stop my period
  5. what could stop a car from starting
  6. what would stop diarrhea
  7. what would stop you from being drafted
  8. what could stop your car from starting
  9. what could stop me from getting pregnant
  10. what would stop you from getting drafted
  11. what could stop implantation
  12. what could stop global warming
  13. what could stop climate change
  14. what could stop your period from coming
  15. what could stop your period
  16. what could stop menstruation
  17. what could stop brexit
  18. what could stop periods
  19. what could stop ovulation
  20. what could stop me getting a mortgage

Is that me doing something wrong or some known bug of using scope operator ([...arr]) with Date()/Date.UTC() constructor? What confuses me: x = [2015,5,1]; //(3) [2015, 5, 1] new Date(2015, 5, 1); //...

Is that me doing something wrong or some known bug of using scope operator ([...arr]) with Date()/Date.UTC() constructor? What confuses me: x = [2015,5,1]; //(3) [2015, 5, 1] new Date(2015, 5, 1); //...

I can't seem to pass Vue data into Vue component from an inline template. I'm getting this error instead: vue.min.js: Uncaught TypeError: Cannot read property 'type' of undefined Below is my ...

I can't seem to pass Vue data into Vue component from an inline template. I'm getting this error instead: vue.min.js: Uncaught TypeError: Cannot read property 'type' of undefined Below is my ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I have a list of objects with a property called created: let objs = [ { id: "1", created: "2019-02-12 00:00:00" }, { id: "2", created: "2018-02-12 00:00:00" }, { id: "3", created: "2017-02-...

I have a list of objects with a property called created: let objs = [ { id: "1", created: "2019-02-12 00:00:00" }, { id: "2", created: "2018-02-12 00:00:00" }, { id: "3", created: "2017-02-...

  1. records cannot be deleted with this form access