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

82
Vistas
Splitting string into array then using one of the values to be displayed in JavaScript

I have the code below which is in JSX format. r.invoice_details gives me an output that looks like this

{"rate":1522,"quantity":1,"discount":null,"itemName":"Gold Members club (offline)","amount":1522,"noEdit":true}

It's in a form of string. All I want is itemName inside the string to be displayed. What's the best way to write as an inline function?

{
  id: "itemName",
  label: "Item",
  customCell: (r, i) => {
    return <td key={`${i}-itemName`}>
      {r.invoice_details}
      </td>;
  }
},
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can use JSON.parse()

const json = '{"rate":1522,"quantity":1,"discount":null,"itemName":"Gold Members club (offline)","amount":1522,"noEdit":true}';
const obj = JSON.parse(json);

console.log(obj.itemName);

So your end code will look something like this,

{
  id: "itemName",
  label: "Item",
  customCell: (r, i) => {
    return <td key={`${i}-itemName`}>
      {JSON.parse(r.invoice_details).itemName}
      </td>;
  }
},
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try Object.values after extractiong JSON.parse()

  let json = JSON.parse(r.invoice_details)
   let inv =   Object.keys(json)
   let inv2 = Object.values(json)
   let Id = inv2[inv1.indexOf("itemName")]

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the JSON.parse() function:

{JSON.parse(r.invoice_details).itemName}

So your final code will look like this:

{
  id: "itemName",
  label: "Item",
  customCell: (r, i) => {
    return <td key={`${i}-itemName`}>
      {JSON.parse(r.invoice_details).itemName}
      </td>;
  }
},
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