I am facing an issue with using the index of a forEach loop to access an array index in my code. It seems to work when I use a number directly, but not when I try to use the index variable. Any suggestions or insights on how to resolve this?
let postive = this.graphData.results[0].values
let finalPostive = []
// formatting the array
postive.forEach(function (item, index) {
self.makeArray(finalPostive, item, index)
})
// function to create array elements
makeArray: function (newArray, item, index) {
// Accessing by using a number works fine
obj["name"] = this.graphData.results[0].id
// However, using the index causes an error:
// "TypeError: Cannot read property 'id' of undefined"
obj["name"] = this.graphData.results[index].id
},