Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!