Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // Spread and Rest Operators
  12. //spread operator, can copy array or add items to obj
  13. //breaks up array or obj elements
  14. "use strict";
  15.  
  16. var number = [1, 2, 3];
  17. var newNumber = [].concat(number, [4]);
  18.  
  19. console.log(newNumber);
  20.  
  21. //rest operator, typically used in a function, merges args into array
  22. var filterArr = function filterArr() {
  23. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  24. args[_key] = arguments[_key];
  25. }
  26.  
  27. return args.filter(function (elt) {
  28. return elt === 1;
  29. });
  30. };
  31.  
  32. console.log(filterArr(1, 2, 3));
  33. </script>
  34.  
  35.  
  36.  
  37. <script id="jsbin-source-javascript" type="text/javascript">// Spread and Rest Operators
  38. //spread operator, can copy array or add items to obj
  39. //breaks up array or obj elements
  40. const number = [1, 2, 3];
  41. const newNumber = [...number, 4];
  42.  
  43. console.log(newNumber);
  44.  
  45. //rest operator, typically used in a function, merges args into array
  46. const filterArr = (...args) => {
  47. return args.filter(elt => elt === 1);
  48. }
  49.  
  50. console.log(filterArr(1,2,3));</script></body>
  51. </html>
Add Comment
Please, Sign In to add comment