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

110
Views
Select loop react js with array of objects

I have an array of objects

let arr= [0: {received: "Return Received", approved: "Approved", rejected: "Rejected"} 1: {authorized: "Authorized", received: "Return Received"}}

I want to push data into <option></options>

where first set should make an option set like fist set create and option and second next option when executing in loop

ex :

<Select><option key="received" >Return Received</options<option key="approved">Approved</options><option key="rejected">Rejected</options><Select>

<Select><option key="authorized" >Authorized</options><option key="received">ReturnReceived</options><Select>

I tried the below code but im getting all result in single option

const listItems = Object.entries(arr).map(([key, value]) => (
        console.log(Object.keys(arr[0]).length),
        Object.entries(value).map(([name, data]) => (
            <option key={name}>{name}</option>
        ) 
        )
    )
    );

<Select native={true}>{listItems}<Select>

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

0

You should be creating one <select> per key, but you're only creating one in total. Try something like this:

  const obj = {
    0: {
      received: "Return Received",
      approved: "Approved",
      rejected: "Rejected"
    },
    1: {
      authorized: "Authorized",
      received: "Return Received"
    }
  };

  const listItems = Object.entries(obj).map(([key, value]) => (
    <select key={key}>
      {Object.entries(value).map(([name, data]) => (
        <option key={name}>{name}</option>
      ))}
    </select>
  ));

Here's a sandbox: https://codesandbox.io/s/bitter-feather-emizf

It's also a little weird that you're calling arr an array and you say you're pushing data into it, but then using Object.entries and what seems like object syntax for it. Anyway, I assumed it's an object above. Just in case you're stuck on the array aspect, I added an array structure too:

  const arr = [
    {
      received: "Return Received",
      approved: "Approved",
      rejected: "Rejected"
    },
    {
      authorized: "Authorized",
      received: "Return Received"
    }
  ];

  const arrList = arr.map((value, index) => (
    <select key={index}>
      {Object.entries(value).map(([name, data]) => (
        <option key={name}>{name}</option>
      ))}
    </select>
  ));
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!