Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var a = [1,2,3,4];
- // a의 원소를 돌면서, 값을 변경시킨 후에 새로운 배열로 만들어서 반환
- var mapped = a.map(function(v) {
- return v * 2;
- });
- // 기존 배열과 비교
- console.log(a, mapped);
- // 배열 탐색
- var newArr = ["apple", "tomato"].map(function(v, i) {
- return i + "번째 과일은 " + v + "입니다";
- });
- // 배열 출력
- console.log(newArr);
- /*
- 0 "0번째 과일은 apple입니다"
- 1 "1번째 과일은 tomato입니다"
- */
Add Comment
Please, Sign In to add comment