-1

Given two arrays of integers:

const arr3 = [11, 12, 13, 14, 15,];
const arr4 = [16, 17, 18, 19, 20,];

Using For-Loop, how do I add up each element in the same position and create a new array containing the sum of each pair? Both arrays are of the same length.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 2
    If you post what you tried, someone may be able to help you fix/finish it. – Scott Hunter Jul 07 '21 at 18:55
  • Welcome to SO! Can you share what you have tried so far? Also, for what it is worth, this feels like it may be a homework question; if so, I'd recommend you review the post [How Do I Ask And Answer Homework Questions?](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) – Alexander Nied Jul 07 '21 at 18:56
  • Use the `Array.prototype.map()` function. It receives the index as an argument, so it can use that to access the corresponding element in the second array. – Barmar Jul 07 '21 at 18:57
  • *"Using For-Loop, how do I add up each element in the same position*". Yes, use a for loop through the array and get the value for the same index from both arrays and add them up. Which part are you having trouble with? – adiga Jul 07 '21 at 19:06

1 Answers1

2
var results = [];

for (var i=0; i < arr3.length; i++) {
  results.push(arr3[i] + arr4[i])
}