[Solved] sum of two array in Node.js [duplicate]


A contains numbers while B contains strings. You want to cast to numbers first to make the computation, and then cast the result to string to get a string; you can use .toFixed to get a given number of precisiong (according to your expected output).

    A = [
                    25.8,                 27,
      24.099999999999998, 30.070000000000004,
                    34.3, 34.300000000000004,
                    34.3,                 33,
                    29.2,               29.2,
                    27.6, 28.999999999999996,
      29.310000000000002, 27.000000000000004
    ]
    
    B = [
      '0.00387000', '0.00472000',
      '0.00534000', '0.00460000',
      '0.00060000', '0.00032000',
      '0.00053000', '0.00327000',
      '0.00217000', '0.00217000',
      '0.00460000', '0.00415000',
      '0.00852000', '0.02241000'
    ]
    
    C = A.map((a,i)=> (a+Number(B[i])).toFixed(8))
    console.log(C)

solved sum of two array in Node.js [duplicate]