Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //** REST & SPREAD **//
- // ...(three dots is "rest" operator and "spread" operator)
- //Example of REST
- //REST takes an array and manually breaks it up.
- function a(first,second,...others){
- //first=1
- //second=2
- //others[0]=4
- //others[1]=8
- //other[2]=16 ***check arr variable below for reference***
- }
- let arr=[1,2,4,8,16];
- a(arr[0],arr[1], arr[2], arr[3], arr[4]);
- a(arr);
- //Example of SPREAD
- function b(id, name, address){
- };
- let person=[75,"steve", "123 main", "ottawa", "on", "K2G1V8", "Canada", ....];
- //take the array and spread it into as many values as there are in the array, then the function will only use the values it needs.
- b(...person);
- //function "b" would be passed the next values (id=75, name=steve, address=123 main)
- //By using SPREAD operator(...) turn an array => separe values.
- let myArray[]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement