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

158
Views
How do I access object's values inside of Array in React?

I'm working on a React App where I'm passing an array that holds various values for each index and passing it to a prop, but for some reason its not displaying the text inside of my h1. I'm not receiving an error for it, and I've tried researching a bit but I'm unable to find any concrete information.

State: var [editTask, setEditTask] = useState([]);

How I'm writing to the state(works correctly) Keep in mind, im only storing 1 element, this will never have multiple:

setEditTask([{
  text: todo.text,
  status: todo.status,
  id: todo.id,
  priority: todo.priority,
}]);

How i'm trying to get the text from the array:

return (
  <div>
    <h1>{props.editTask.id}</h1>
  </div>
)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try using the native javascript Object.values() method.

about 4 years ago · Juan Pablo Isaza Report

0

If you are storing only one element you don't need an array of objects. Can be done with a single object.

const [editTask, setEditTask] = useState({});

useEffect(() => {
  setEditTask({
    ...todo,
  });
}, [todo]);

// Inside component
return (
  <div>
    {Object.values(props.editTask).map((val) => (
      <h1>{val}</h1>
    ))}
  </div>
);

Without changing current structure

return (
  <div>{ editTask.map((val) => <h1>{val.status}</h1>)}</div>
);
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!