Guest User

Untitled

a guest
Jun 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. var myNums = [1, 2, 3, 4, 5];
  2.  
  3. function doubleNum(num) {
  4. return num * 2;
  5. }
  6.  
  7. // Built-in Array.prototype.map function, using anonymous function argument
  8. var doubledNums = myNums.map(function(num) {
  9. return num * 2;
  10. });
  11. console.log(doubledNums); // logs "[2, 4, 6, 8, 10]"
  12.  
  13. // Built-in Array.prototype.map function, using named callback argument
  14. var otherDoubledNums = myNums.map(doubleNum);
  15. console.log(otherDoubledNums); // logs "[2, 4, 6, 8, 10]"
Add Comment
Please, Sign In to add comment