I'm building an app with Babel/ES6. I want to disable all form elements for a view-only version of it, so I did this:
let form = document.getElementById('application-form')
let elements = form.elements
I expected to be able to do this, instead of using a regular old for
loop (which did work):
elements.forEach((el) => {
el.disabled = true
})
but I got TypeError: elements.forEach is not a function
The strange thing is if I console.log(elements)
in the Chrome dev console it exactly like an array with a bunch of input
objects. It doesn't display with the Object
notation for objects, and all of the keys are integers. I'm thinking it's some sort of pseudo array, but I wouldn't even know how to find that out.
EDIT: short answer it's not an array it's an HTMLCollection. see Why doesn't nodelist have forEach?
*UPDATE*
Per this answer, nodelist
now has the forEach
method!