0

I got the following error

Cannot read property 'overview' of undefined

I cannot figure out what this is.

<template>
  <tr v-for="(row, fold) of perFold" :key="fold">
    <td>{{ fold + 2 }}</td>
    <td>{{ row.correct }}</td>
    <td>{{ row.incorrect }}</td>
    <td>{{ row.accuracy.toFixed(2) }}%</td>
  </tr>
</template>


<script>
export default {
  methods: {
    perFold () {
      let data = this.result[this.attr].knn

      let perFold = []

      for (let i = 2; i <= 10; i++) {
        let label = (i < 10 ? '0' : '') + i;
        let fold = data[`fold-${label}`]
        perFold.push(fold[fold.overview.bestAttr])
      }

      return perFold
    }
  }
}
</script>

Then in the browser, I get the following error

TypeError Cannot read property 'overview' of undefined

When I comment this line

perFold.push(fold[fold.overview.bestAttr])

I then do not have any error, but the results expected in my browser are empty.

kissu
  • 40,416
  • 14
  • 65
  • 133
  • Formatted to make it readable to a minimal degree. – kissu Nov 29 '21 at 11:12
  • `fold` is in some cases falsy (null, undefined), hence why you cannot access `overview` here. – kissu Nov 29 '21 at 11:13
  • I'm not really sure about the actual thing you're trying to achieve here, it could be nice to have an explanation of what is attended an probably also a [repro] if you want to have this one improved. – kissu Nov 29 '21 at 11:15

1 Answers1

0
        perFold.push(fold[fold[i].overview.bestAttr])

fold is a array. Because of that you need to specify loop index.