In javascript, Spread operator allows to mention elements of the items such as array/strings/objects one by one at the required place

Spread behaves just like when we take out playing cards from the box & spread them to play

#javascript

Check out the thread below to know more
👩‍🏫 Spread syntax can be used with

☝️elements that can be iterated/looped such as array or string
☝️objects

Note: the spread syntax loops through the object properties & add the key-value pairs to the new object
👩‍🏫 Spread syntax is accepted at three distinct places

1⃣ Function call - arguments list
myFunction(a, ...iterableObj, b)

2⃣ Array literals
[1, ...iterableObj, '4', 'five', 6]

3⃣ Object literals
{ ...obj, key: 'value' }
👩‍🏫 Spread in function calls

In cases, where you need to pass elements of an array as the arguments in a function call; the spread syntax can be used to mention arguments one by one
👩‍🏫 Spread in array literals is a powerful combination. It can be used to

☝️copy an array - one level deep
☝️merge two arrays
☝️create a new array by inserting the existing array at any index
👩‍🏫 Spread in object literals can be used to create/copy a new object or merge two objects
Follow me - @ojhabhumika28 for more threads, tips and quizzes on JavaScript ✨

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Bhumika Ojha | Javascript

Bhumika Ojha | Javascript Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @ojhabhumika28

Jan 26
☝️The destructuring expression allows the extraction of properties from objects into distinct variables with the help of a minimum code

📌Check out the thread below to know more Image
☝️Destructure Syntax for objects
Note: ensure property name and variable name are same while destructuring an object Image
☝️Default value
- each destructured property can have a default value
- default value can also be any expression
- default value/expression is used when the property is not present or has a value undefined
- not used if the value of a property is null Image
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(