Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // Spread and Rest Operators
- //spread operator, can copy array or add items to obj
- //breaks up array or obj elements
- "use strict";
- var number = [1, 2, 3];
- var newNumber = [].concat(number, [4]);
- console.log(newNumber);
- //rest operator, typically used in a function, merges args into array
- var filterArr = function filterArr() {
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- return args.filter(function (elt) {
- return elt === 1;
- });
- };
- console.log(filterArr(1, 2, 3));
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// Spread and Rest Operators
- //spread operator, can copy array or add items to obj
- //breaks up array or obj elements
- const number = [1, 2, 3];
- const newNumber = [...number, 4];
- console.log(newNumber);
- //rest operator, typically used in a function, merges args into array
- const filterArr = (...args) => {
- return args.filter(elt => elt === 1);
- }
- console.log(filterArr(1,2,3));</script></body>
- </html>
Add Comment
Please, Sign In to add comment