Skip to content

Instantly share code, notes, and snippets.

@tripdog
Last active June 19, 2021 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripdog/446c5b203dbd91ff31fe2ae8e8cdebac to your computer and use it in GitHub Desktop.
Save tripdog/446c5b203dbd91ff31fe2ae8e8cdebac to your computer and use it in GitHub Desktop.
Write a function that takes an array of numbers add 10 to every element of the array using forEach( ) and returns a new array.

Write a function that takes an array of numbers and adds 10 to every element of the array using the forEach( ) method and returns a new array.

const anotherArr = [ 12, 11, 12, 13, 14 ]
let addToArr = []
anotherArr.forEach(num => {
   addToArr.push(num + 10)
})
console.log(addToArr)

//Logs [ 22, 21, 22, 23, 24 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment