Spread Operator is a magical operator that is used with three dots i.e. "..." This is can be used with Arrays or Objects. It's primarily used to extract values of the Arrays or the properties of the Objects
For personalized coaching contact: dhandrohit@gmail.com
Happy Coding !
function demo(){
var cities = ["Toronto","Vancouver"];
console.log([...cities]);
var t = {
name: "Rohit",
cities : [...cities]
}
console.log({...t});
}
demo();
If we run the above program, the following output will be generated: [ 'Toronto', 'Vancouver' ]
{ name: 'Rohit', cities: [ 'Toronto', 'Vancouver' ] }
So we can see that there two different ways by which Spread Operator is used i.e. [] and {}For personalized coaching contact: dhandrohit@gmail.com
Happy Coding !
Comments