Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
create card using array of data react

hi everyone I have data given below by using this data I just want to create a cart click on this link to check what kind of cart I want to design from this data

 const result = [
{
  name: 'shanu',
  label: ['ak', 'pk', 'plk', 'k'],
  value: [1, 2, 3, 5],
},

];

// what i did

 {result.map((el) => {
        return (
          <div>
            <h1>{el.name}</h1>
            <div className="vart">
              <div>
                {el.label.map((e) => {
                  return <p>{e}</p>;
                })}
              </div>
              <div>
                {el.value.map((e) => {
                  return <p>{e}</p>;
                })}
              </div>
            </div>
          </div>
        );
      })}
.vart {
  display: flex;
  flex-direction: row;
}

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can access the value according to the index of the label as below. You can use a CSS grid system to show a two-column view.

export default function App() {
  const result = [
    {
      name: "shanu",
      label: ["ak", "pk", "plk", "k"],
      value: [1, 2, 3, 5]
    }
  ];

  return result.map((el) => {
    return (
      <div>
        <div className="header">{el.name}</div>
        <div className="grid-container">
          {el.label.map((e, index) => {
            return (
              <div
                className="grid-item"
                style={{ textAlign: index % 2 === 0 ? "left" : "right" }}
              >
                {e} : {el.value[index]}
              </div>
            );
          })}
        </div>
      </div>
    );
  });
}

Following styles will organise the grid with right aligning the second column.

.header {
  color: #ffffff;
  background-color: #4473c4;
  padding: 10px 20px;
}

.grid-container {
  display: grid;
  grid-template-columns: auto auto;
}

.grid-item {
  padding: 10px 20px;
  color: #ffffff;
  background-color: #91cf50;
}

HTML Output

enter image description here

Code Sandbox

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to link value and label this way:

ak => 1
pk => 2
plk => 3
k => 5

It would be better practice to change your data structure and move them aside. It avoids running in cases where label[x] is defined, but value[x] is not:

export default function App() {
  const result = [
    {
      name: "shanu",
      items: [
        { label: "ak", value: 1 },
        { label: "pk", value: 2 },
        { label: "plk", value: 3 },
        { label: "k", value: 5 },
      ],
    }
  ];

  return result.map((el) => {
    return (
      <div>
        <h1>{el.name}</h1>
        <div className="vart">
          <div>
            {el.items.map((e, index) => {
              return (
                <p>
                  {e.label} : {e.value}
                </p>
              );
            })}
          </div>
        </div>
      </div>
    );
  });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda