Guest User

Untitled

a guest
Dec 15th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. var a = [1,2,3,4];
  2.  
  3. // a의 원소를 돌면서, 값을 변경시킨 후에 새로운 배열로 만들어서 반환
  4. var mapped = a.map(function(v) {
  5. return v * 2;
  6. });
  7.  
  8. // 기존 배열과 비교
  9. console.log(a, mapped);
  10.  
  11. // 배열 탐색
  12. var newArr = ["apple", "tomato"].map(function(v, i) {
  13. return i + "번째 과일은 " + v + "입니다";
  14. });
  15.  
  16. // 배열 출력
  17. console.log(newArr);
  18.  
  19. /*
  20. 0 "0번째 과일은 apple입니다"
  21. 1 "1번째 과일은 tomato입니다"
  22. */
Add Comment
Please, Sign In to add comment