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

206
Views
TypeError: Cannot read properties of undefined reading 'length'

I'm getting this error within the equipmentExercises block while fetching the data from the API. I have already checked the datatype which is an array. And equipmentExercises.length is showing an undefined datatype.

const SimilarExercises = ({ targetMuscleExercises, equipmentExercises }) => {
    console.log(equipmentExercises);
    return (
        <Box sx={{ mt: { lg: '100px', xs: '0px' } }}>
            <Typography
                sx={{ fontSize: { lg: '44px', xs: '25px' }, ml: '20px' }}
                fontWeight={700}
                color="#000"
                mb="33px"
            >
                Similar <span style={{ color: '#FF2625', textTransform: 'capitalize' }}>Target Muscle</span> exercises
            </Typography>
            <Stack direction="row" sx={{ p: 2, position: 'relative' }}>
                {targetMuscleExercises.length !== 0 ? <HorizontalScrollbar data={targetMuscleExercises} /> : <Loader />}
            </Stack>

            <Typography
                sx={{ fontSize: { lg: '44px', xs: '25px' }, ml: '20px', mt: { lg: '100px', xs: '60px' } }}
                fontWeight={700}
                color="#000"
                mb="33px"
            >
                Similar <span style={{ color: '#FF2625', textTransform: 'capitalize' }}>Equipment</span> exercises
            </Typography>
            <Stack direction="row" sx={{ p: 2, position: 'relative' }}>
                **{equipmentExercises.length !== 0 ? <HorizontalScrollbar data={equipmentExercises} /> : <Loader />}**
            </Stack>
        </Box>
    );
};
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

This is because your equipmentExercises and targetMuscleExercises might be null at first place.

You can fix this by adding a check like this: equipmentExercises?.length !== 0 or equipmentExercises && equipmentExercises.length !== 0

about 4 years ago · Santiago Trujillo Report

0

You could be passing in a string of an array, instead of an array. Are you able to validate with typeof?

Array and String console.log output look very similar

about 4 years ago · Santiago Trujillo 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!