Asked 7 years ago
18 Jan 2017
Views 1119
web-api

web-api posted

what is use of spread operator in JavaScript ?

what is use of spread operator in JavaScript ?
how one can use spread operator ?

[...iterableObj, 4, 5, 6]


what meaning of ... (spread operator ) , what spread operation does in above code ?
Rasi

Rasi
answered Nov 30 '-1 00:00

it make array to flat value in sequence .
if you know list function in php . spread operaton work same
suppose in php
list(x,y)=array(4,5);//x=4 , y=5

in JavaScript

fuction PrintArray(x,y){
console.log('a[0]= '+x+',a[1]='+y);
}
var a=[1,2];
PrintArray(...a);//a[0]= 1,a[1]=2 


it send array all index to function argument. isnt it magic in JavaScript ?
Post Answer