The JavaScript spread operator (...) is a powerful feature introduced in ES6 that provides a concise and expressive way to work with arrays, object...
For further actions, you may consider blocking this person and/or reporting abuse
You can use the spread operator with anything that is iterable, not just arrays. For example... a string (this is a much better way of splitting a string into characters than using
.split('')
- as it will deal a lot better with Unicode):Generator functions are iterable by default, so this also works:
It is even possible (with some effort) - to make this code work:
For a more detailed explanation, see this article:
JS Magic: Making a Range Syntax for Numbers
Jon Randy 🎖️ ・ Mar 24 '23
Cool! Could you explain the last one?
... i found it in your post! Really cool! Thanx!
Wow, this is really cool!
Spread operator is also handy for converting a collection of HTML elements into an array:
Cool, you didn't forget to mention that the spread operator creates a shadow copy of an object.
Also look at the
structuredClone
function from the global scope.And last but not least. As @jonrandy notes, I also add something (try it):
I was not able to understand one thing that why do you need spread operator for the following cases:
const numbers = [1, 2, 3, 4, 5];
const doubledNumbers = [...numbers].map(num => num * 2);
console.log(doubledNumbers);
&
const numbers = [1, 2, 3];
function sum(a, b, c) {
return a + b + c;
}
console.log(sum(...numbers));
where you could simply pass
numbers
instead of...numbers
In both cases, the output will remain same.
I had some crypto on a Bitcoin wallet that I thought was lost for good. I’d sent my laptop to a variety of top data recovery firms, but with no luck. After seeing a positive comment about ROOTKIT HACKER on “Morning Brew”, I decided to try to recover my wallet one last time. ROOTKIT HACKER was very responsive to emails, and recovered my wallet in just a few days. I was nervous about providing my wallet seed and passphrase, but there really was no need to be uneasy. ROOTKIT HACKER acted honorably and in accordance with our agreement. I would highly recommend using ROOTKIT HACKER services, even if you have nearly given up hope of recovering your wallet. Contact them on Email: rootkithacker1@outlook.com
WhatsApp: +1 (929) 447‑0339
They are Tested and trusted.
JSON.parse(JSON.stringify) does not work for DOM references. Use structuredClone instead
One that I always end up using is.
You have the spread operator in the wrong place. Your code will cause a syntax error. I think you mean:
Nice post! 😊
This useful post helped me refresh what I had studied..