Object returning NaN when sum values

前端 未结 3 1728
名媛妹妹
名媛妹妹 2020-12-02 02:23

I\'ll admit I\'m weak in JavaScript and JSON. I\'ve spent a lot of time attempting to figure out why numbers from my objects returns NaN when they are added together. With t

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 02:31

    I like this approach. It basically sets the value to 0 on the first iteration when jan doesn't exist.

    jan = (jan || 0) + parseFloat(data[i].jan);
    

提交回复
热议问题