Are they all checked?

Simplest way to check whether all checkbox input fields checked or not; by converting a NodeList to an Array using ES6 ... spread operator so we can attach every() method to it;

Checkout the Are they all checked? Demo on jsfiddle

[...document.querySelectorAll('input')].every(checkbox => checkbox.checked)
Did you find this post useful? Show some love!
DISCUSSION (5)

What would be the benefit for using a spread operator instead of Array.from()?

Thanks Arden! You can definitely do the same thing with Array.from, but in my case, the ... is better use IMO. Less code, easy to remember, plus performance. Cheers

Ah btw, I didn't knew Array.from took in two arguments, so an alternative could be

Array.from(document.querySelectorAll('input'), checkbox => checkbox.checked);

Correct me if I'm wrong.

I kinda like Array.from() because it's so verbose and easy readable, but I guess that's also because not everyone (read: me) is used to spread operators yet. Thanks for the clarification!

Also

Array.prototype.every.call(document.querySelectorAll('input'), checkbox => checkbox.checked)
Classic DEV Post from Jul 28

What Defines a "Junior" Developer? πŸ€·πŸ»β€β™€οΈ

How do you define a β€œJunior” Developer? Is it by the amount of experience they ...

READ POST
Follow @brendazam to see more of their posts in your feed.
Mahmoud Elmahdi
Software Engineer w/ a Designer's state of mind
More from @_elmahdim
Safe, reliable Browser sniffing
#javascript #browser #detection #desktop
React Firebase Authentication
#react #firebase #authentication #javascript
Trending on dev.to
CookList : From idea to project to finished app
#angular #spotify #webdev #javascript
Setting up tape testing framework for basic frontend development
#javascript #testing #beginners
Canceling setInterval in React
#react #javascript
Mint vs JavaScript (stack)
#mintlang #javascript #webdev
You Should be Using esm
#javascript #esm #es6
Demystifying Webpack
#webdev #frontend #backend #javascript
How to ask good questions as a developer
#beginners #devtips #learning #webdev
Single keyword expressions in JavaScript
#javascript #single #expression #keyword