Great stuff. Note that spread operator works also in deconstruction too, not only construction:
Take first (or n first) fields of an array:
let [first, ...rest] = [1, 2, 3, 4, 5]; // first == 1 // rest == [2, 3, 4, 5]
Or as function definition:
function giveMeAllTheParams(...params) { console.log(`You gave me ${params.length} params`); } giveMeAllTheParams(1, 2, 3, 4, 5); // You gave me 5 params
All great examples!
Likewise for objects, can be used to create a new one that omits certain properties.
const {a, ...rest} = {a: 1, b: 2, c: 3};
I always forget this since there seem to be more places to use the construction functionality. Thanks for the reminder!
Good one😍
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great stuff. Note that spread operator works also in deconstruction too, not only construction:
Take first (or n first) fields of an array:
Or as function definition:
All great examples!
Likewise for objects, can be used to create a new one that omits certain properties.
I always forget this since there seem to be more places to use the construction functionality. Thanks for the reminder!
Good one😍