Thanks to ES6 and the likes of Babel, writing JavaScript has become incredibly dynamic, from new language syntax to custom parsing like JSX. I've become a big fan of the spread operator, three dots that may change the way you complete tasks within JavaScript.
test the examples in the console!
Calling Functions without Apply
Convert arguments or NodeList to Array
Convert arguments or NodeList to Array
Much like copying arrays, we've used Array.Prototype.slice to convert NodeList and arguments objects and to true arrays, but now we can use the spread operator to complete that task:
[...document.querySelectorAll('div')]
The Axel Rauschmayer has 2 more (see comments)
Convert iterables to Arrays (not just arguments and NodeList):
> [...new Map().set(true, 'yes').set(false, 'no')] [ [ true, 'yes' ], [ false, 'no' ] ]
❤ Eliminate duplicates from an Array:
> const arr = [7, 3, 1, 3, 3, 7]; > [...new Set(arr)] [ 7, 3, 1 ]