DEV Community

Cover image for What's the Spread Operator in Javascript and How to Use it

What's the Spread Operator in Javascript and How to Use it

Gaël Thomas on October 18, 2020

In this short tutorial, you will learn Spread Operators in JavaScript and how to use them. ES6 introduced new features in JavaScript. One of the f...
Collapse
 
crimsonmed profile image
Médéric Burlet • Edited

I think you could have added an example on changing properties when copying an object:


const user = {
  firstName: "John",
  lastName: "D",
  age: 25,
};

const newUser = {...user, firstName: "Jane"}

console.log(newUser);
// Output: {
//  firstName: "Jane",
//  lastName: "D",
//  age: 25,
//  jobName: "Developer"
//};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gaelgthomas profile image
Gaël Thomas • Edited

Hello,
Thank you for the feedback! I added your suggestion to the article.
It's a good example that can help people to understand better how to create or copy objects! (I think you wanted to write about objects, not arrays?)

Collapse
 
crimsonmed profile image
Médéric Burlet

Oh yes object haha didn't see the typo

Thread Thread
 
gaelgthomas profile image
Gaël Thomas • Edited

Haha no problem! 😃 👍

Collapse
 
breadandwater profile image
Adrian Paniagua Sanchez

Really good explication of spread operator. Really clear and easy to understand! Thanks for that!

Collapse
 
gaelgthomas profile image
Gaël Thomas

Thank you for your amazing feedback! 😃

Collapse
 
merkrynis profile image
Julien Bouvet

Nice, quick and easy, thanks a lot :)

Collapse
 
gaelgthomas profile image
Gaël Thomas

Thank you, I'm glad you like it! 😁

Collapse
 
kiraniyerdev profile image
Kiran Iyer

Amazing thread. Now I know how to use spread operator. Bring it on! lol

Collapse
 
gaelgthomas profile image
Gaël Thomas

Hey, thank you! It's so cool, have fun using them!

Collapse
 
juanccq profile image
Juan Carlos Choque Quispe

Thanks for the post.

Collapse
 
gaelgthomas profile image
Gaël Thomas

😁😁

Collapse
 
psargedev profile image
psargedev

Thanks. This was clear and concise!

Collapse
 
gaelgthomas profile image
Gaël Thomas

Thank you for this feedback! 😊