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!

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 Feb 12

I just got a Raspberry Pi 3. What can I do with it?

Just got a Raspberry Pi 3 setup and it's my first one. If you own a Raspberry P...

READ POST
Follow @michael to see more of their posts in your feed.
Mahmoud Elmahdi
Software Engineer
More from @_elmahdim
React Firebase Authentication
#react #firebase #authentication #javascript
JavaScript String Methods You Probably Haven’t Heard Of and that's Okay
#javascript #string #reference #method
Trending on dev.to
Context in React
#react #javascript
Introducing JavaScript Objects
#beginners #javascript #webdev
React Native is dead, long live React Native
#react #reactnative #javascript #ios
Node.js Top 10 Articles — June 2018
#node #javascript #webdev #tech
Sails.js is a Node.js MVC framework inspired by Ruby on Rails
#mvc #webdev #javascript #node
Coding Concepts - Generics
#webdev #typescript #beginners #javascript
Back to basics: Naming
#naming #javascript #programming #discuss
How to build a real-time editable data table in Vue.js
#javascript #vue #realtime