# Iterate over Arrays with map excercise JS

**URL:** <https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515>\
**Category:** General\
**Created:** [December 17, 2016, 7:07pm UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515 "2016-12-17T19:07:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![briannyeko](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@briannyeko](https://forum.freecodecamp.org/u/briannyeko)\
**Post date:** [December 17, 2016, 7:07pm UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515/1 "2016-12-17T19:07:14Z")

</div>

having trouble solving this, anyone have a hint how to do this?:

var oldArray = [1,2,3,4,5];

// Only change code below this line.  
var addThree = oldArray.map(function(val){  
return val + 3;  
});  
console.log(addThree); // returns [4, 8, 12]  
console.log(oldArray);  
var newArray = oldArray;

---

<div class="post-metadata">

**Author:** ![briannyeko](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@briannyeko](https://forum.freecodecamp.org/u/briannyeko)\
**Post date:** [December 17, 2016, 11:30pm UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515/3 "2016-12-17T23:30:54Z")

</div>

anyone have any hints???

---

<div class="post-metadata">

**Author:** ![JohnL3](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnl3/32/16459_2.png) [@JohnL3](https://forum.freecodecamp.org/u/JohnL3)\
**Post date:** [December 17, 2016, 11:57pm UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515/4 "2016-12-17T23:57:53Z")

</div>

you actually have what you need … plus stuff you dont need is why its failing …

just change last line var newArray = oldArray to var newArray = addThree

it passes then … if you dont understand why post back

---

<div class="post-metadata">

**Author:** ![annajuare](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@annajuare](https://forum.freecodecamp.org/u/annajuare)\
**Post date:** [December 18, 2016, 4:19am UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515/5 "2016-12-18T04:19:05Z")

</div>

The solution is:

var oldArray = [1,2,3,4,5];  
//only change code below this line  
var newArray = oldArray.map(function(val) {  
return val + 3;  
});  
console.log(addThree);  
console.log(oldArray);

Hope that helps.

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [December 18, 2016, 5:19am UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515/6 "2016-12-18T05:19:28Z")

</div>

@annajuare: please do not post spoilers without making an effort to mask them. You can use spoiler tags like @PortableStick did in one of your other posts.

Please also make the effort to properly format your code, as you have been asked to do several times before.

If you need help doing either of these things, I will happily explain them in more detail.

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:10am UTC](https://forum.freecodecamp.org/t/iterate-over-arrays-with-map-excercise-js/66515/7 "2021-01-16T06:10:52Z")

</div>

Closed on January 16, 2021, 6:10am UTC


