I’m trying to get data from an array like object using foeach but it’s giving me the following error:
Uncaught TypeError: Cannot read property 'call' of undefined
The array like object contains children elements of a div but I do not know why the property is undefined. Please see my code here. Once inside jsFiddle, you can click the blue button and check the console log to see the error message. Thank you.
Hi @liagapi555, using forEach.call() (note the camel case BTW) is a way to apply array methods to array like objects such as your HTML collection; it works this way:
const nodes = document.getElementById('something').children
Array.prototype.forEach.call(nodes, node => {
// do something with the node
})
A better way though is to just convert your object to an actual array from the first: