Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda