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

186
Views
problem/weird bug with my code ( can't access property "map", Object.values(...)[0] is undefined)

I have a problem with my react code. It keeps saying that I can't access property "map", because Object.values(...)[0] is undefined. this will usually mean that whatever is inside my object values is unreachable, or doesnt exit. However it does. I just need to remove pic and grades from persons for it to work. Sometimes i need refresh the page a few times and it will work as well.

anyone know why this might be happening.


import axios from 'axios'
import { useState, useEffect } from 'react'
import './App.css'

function App() {
  const [students, setStudents] = useState([])

  const hook = () => {
    axios
      .get('https://api.hatchways.io/assessment/students')
      .then(response => {
        console.log("promise filled")
        setStudents(response.data)
      })
  }

  useEffect(hook, ([]))
  console.log((Object.values(students)[0]))
  const Person = ({ firstname, lastname, email, company, skill, grades
    , pic }) => {

    const temp = grades.reduce((a, b) => Number(a) + Number(b), 0)
    const average = temp / grades.length

    return <>
      <div>
        <img src={pic} />
        <h1>{firstname}  {lastname}</h1>
        <p>Email: {email}</p>
        <p>Company: {company}</p>
        <p>Skill: {skill}</p>
        <p>Average: {average}%</p>



      </div>
    </>

  }


  return (
    <div class = "wrapper">
      {((Object.values(students))[0]).map(person =>
        <Person

          firstname={person.firstName}
          lastname={person.lastName}
          email={person.email}
          company={person.company}
          skill={person.skill}
          pic={person.pic}
          grades={person.grades}
          key={person.id}


        />

      )}






    </div>

  )




}


export default App;

about 4 years ago · Juan Pablo Isaza
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!