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

150
Views
Nested JSON array displaying as [Object Object] in TextField

I have two sets of JSON, Set 1 and Set 2. Set 1 (sizingData) being mapped to textFields like this:

const fillTextField = () => {
    let result = [];
    var keys = Object.keys(sizingHistory);
    keys.forEach(function (key) {
        result.push(sizingHistory[key]);
    });
    return( 
        {result?.map((data) => {
            return ( <TextField variant="outlined" value={data} /> );
        })}
    )
}

I want to map Set 2 (sizingHistory) similarly, but I am getting [Object Object] in the textField rather than the SizingId & SizingComments. This is my attempt at mapping sizinhHistory:

const [sizingHistory, setSizingHistory] = useState("");
const fillHistoryTextField = () => {
    let result = [];
    var keys = Object.keys(sizingHistory["sizinghistory"]);
    keys.forEach(function (key) {
        result.push(sizingHistory["sizinghistory"][key]);
    });
    return (
        {result?.map((data) => {
            return ( <TextField variant="outlined" value={data} /> );
        })}
    )
}

Set 1

{
    "SizingId": 20448,
    "SizingComments": "This is a comment",
}

Set 2

{
    "sizinghistory" : [
        "SizingId" : 20448,
        "SizingComments": "Old Comment",
    ]
}

The fetch function for both sizingData & sizingHistory are called in their own handleOpen functions. UseEffect cannot be used in this case as data is only displayed when a user selects a row in a table containing a SizingId.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have [Object object] as JS is converting an object to string on Set2, this happens because data.seizingHistory is an array and you have to iterate through it then through the keys of the object inside to get all the data on the text inputs.

This should get you what you need

const [sizingHistory, setSizingHistory] = useState("");
const fillHistoryTextField = () => {
    let result = [];

    (sizingHistory["sizinghistory"]).forEach(element => {
      const keys = Object.keys(element);
      keys.forEach(function (key) {
          result.push(element[key]);
      });
    });

    return (
        {result?.map((data) => {
            return ( <TextField variant="outlined" value={data} /> );
        })}
    )
}
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!