TypeError: this.state.exercises.reduce is not a function

I have this function:

getExercisesByMuscles ()  {
  return Object.entries(
      this.state.exercises.reduce((exercises, exercise) => {
    const { muscles } = exercise

    exercises[muscles] = exercises[muscles]
    ? [...exercises[muscles], exercise]
    : [exercise]

    return exercises
  }, {})

It works until recently i started getting this error :


Is there something I’m doing wrong here? please help !

Hello there,

It is difficult to say, from what you have given us. The easiest way to debug is for you to console.log(this.state), and see if it is what you expected. reduce is an Array method. So, if this.state.exercises is not an array, you will get that error.

Hope this helps