If I have two nested arrays within a corresponding array like this:
const nums = [
[4, 23, 20, 23, 6, 8, 4, 0], // Each array consists of 8 items
[7, 5, 2, 2, 0, 0, 0, 0]
];
How can I add the values based on their indexes?
Expected Result:
// For example: 11 is from 4 (array1 - index1) + 7 (array2 - index1)
// and so forth.
[11, 28, 22, 25, 6, 8, 4, 0]
This is what I tried:
// While this solution works for two arrays,
// it wouldn't be dynamic enough to handle more than two arrays
const total = Array.from({ length: 8 }, (_, i) => nums[0][i] + nums[1][i]);