How to Use the Spread Operator (…) in JavaScript

In this guide, you will see examples How to Use the Spread Operator (…) in JavaScript. spread operator split up array element and object properties. Let’s dive into the working example of react js spread operator.

Spread Operator variable Example:

const number = [3,4,5];
const newnumber = [...number, 6, 7, 8];
console.log(newnumber);

OutPut: [3, 4,5, 6, 7, 8]

const newnumber = [number, 6, 7, 8];
console.log(newnumber);

OutPut: [ [3, 4,5], 6, 7, 8]

Spread Operator object Example:

const Person{

name: 'blogindices'

};

const Persongender{

...Person,
gender = 'male';

}

console.log(Persongender);

OutPut: [object, object]{
 gender: 'male',
 name: 'blogindices'
 
}

Hope you are understanding about the spread. In the upcoming tutorials, we will use this a lot so, be command on this, and to get more guides on React, you can join us on our FB social page to the notification.

Stay in touch. Ask Questions.
Lean on us for help, strategies and expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *