Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. //** REST & SPREAD **//
  2. // ...(three dots is "rest" operator and "spread" operator)
  3. //Example of REST
  4. //REST takes an array and manually breaks it up.
  5. function a(first,second,...others){
  6. //first=1
  7. //second=2
  8. //others[0]=4
  9. //others[1]=8
  10. //other[2]=16 ***check arr variable below for reference***
  11. }
  12. let arr=[1,2,4,8,16];
  13. a(arr[0],arr[1], arr[2], arr[3], arr[4]);
  14. a(arr);
  15.  
  16.  
  17. //Example of SPREAD
  18. function b(id, name, address){
  19.  
  20. };
  21. let person=[75,"steve", "123 main", "ottawa", "on", "K2G1V8", "Canada", ....];
  22.  
  23. //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.
  24. b(...person);
  25. //function "b" would be passed the next values (id=75, name=steve, address=123 main)
  26. //By using SPREAD operator(...) turn an array => separe values.
  27. let myArray[]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement