0
data: function () {
         return {
          selectedScope:'',
        }
      },



methods: {
   displayScope: function(newScope) {
            console.log(this.selectedScope)

            var resultArray = []
            this.tableData.forEach(function (data) {

                if (data.iog === this.selectedScope) {   // This is where the error 
                    resultArray.push(data)
                }
            });

        }
}

I can't seem to figure out why i m getting:

Cannot read property 'selectedScope' of undefined

inside the forEach.

Why?

OPK
  • 4,120
  • 6
  • 36
  • 66
  • 1
    Have you tried using an arrow function `(data) => { /*... */ }` in the `forEach` callback? – Mark Nov 28 '18 at 23:41
  • `forEach` also [accepts a `thisArg`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Syntax). – Roy J Nov 28 '18 at 23:51

0 Answers0