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

91
Views
Display element of an array React

I am passing through a variable called 'homeTeam' and when console logged it outputs

    abbreviation: "Uls"
    id: "08ew458ius6f"
    name: "Ulster"

A variable called 'awayTeam' outputs the same array but with data of a different team

I have a bit of code to find out if I need the homeTeam or awayTeam abbreviation;

    const restartTeamAbbrevation = async (homeTeam, startTeamId, awayTeam) => {
    if (startTeamId == {homeTeam.id} ) {
       return homeTeam.abbreviation
    } else {
       return awayTeam.abbreviation
    }}

I then want this value to appear on my front end, i am attempting to use the following code;

        <Modal.Body>
        <Row>
            <Col>
                <div className="d-flex">
                    <span className="py-1">Team: </span>
                    <span className="py-1">{ restartTeamAbbrevation() }</span>
                </div>
            </Col>
        </Row>
        </Modal.Body>

I am getting the error

Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'id')
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Because when you are calling that function, you are not passing the parameters like homeTeam, startTeamId, awayTeam, so when the function is called these values equals to undefined and when you try to access homeTeam.id inside the function, it gives you that error.

about 4 years ago · Juan Pablo Isaza Report

0

Try passing arguments to your restartTeamAbbreviation function. Something like this:

        <Modal.Body>
        <Row>
            <Col>
                <div className="d-flex">
                    <span className="py-1">Team: </span>
                    <span className="py-1">{ restartTeamAbbreviation(homeTeam, startTeamId, awayTeam) }</span>
                </div>
            </Col>
        </Row>
        </Modal.Body>

Also you have some strange condition, you might want to do this instead:

if (startTeamId === homeTeam.id ) ...

And one more thing, restartTeamAbbreciation function doesn't need to be async

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!