# Simple method to add values from two multidimensional arrays

I have two multidimensional arrays where I would like to add the two together into one multidimensional array. Both arrays have 365 sets of two values. The first value of each set would match and I need the second value to be added. I also need to account for null values. Basically:

arr1 = [[1548806400000, 10.104928], [1548979200000, 8.877490002], [1549065600000, null], …]
arr2 = [[1548806400000, 30.103548], [1548979200000, 16.25687], [1549065600000, 11.5302], …]

result = [[1548806400000, 40.208476], [1548979200000, 25.13436], [1549065600000, 11.5302], …]

looking for a simple way to get to the result, hopefully using map or reduce or both…

Why do you show us what code you have tried first using map and/or reduce? Then, we can help guide you, in case you get stuck.

``````const arr1 = [[1548806400000, 10.104928], [1548979200000, 8.877490002], [1549065600000, null]]
const arr2 = [[1548806400000, 30.103548], [1548979200000, 16.25687], [1549065600000, 11.5302]]

let result = []
let ans = 0

arr1.forEach(function (x) {
arr2.forEach(function (y) {
ans = parseFloat(x[1] + y[1])
})
result.push([x[0], ans])
})
``````

If you 100% sure that first value would always match, then `.map()` is your go-to method - map through every element of `arr1` adding element with corresponding index from `arr2` (casting values to `Number` as you go)

*If first value is unique you can treat it as a key and perform `Object.fromEntries()` method on `arr2` and then map it like this:

``````arr1.map(([key, value]) => [key, +value + +obj[key]]);
``````

This way you would guarantee result even if your arrays are out of order