相关疑难解决方法(0)

对象在返回值时返回NaN

我承认我在JavaScript和JSON方面很弱.我花了很多时间试图弄清楚为什么我的对象中的数字在加在一起时会返回NaN.考虑到这一点,下面是我的JSON,存储到变量:

var data = [
    {
        "acc_ext_id": null,
        "cat_code": 10002,
        "cat_ds": "REVENUE",
        "category_id": null,
        "chart_id": null,
        "created_at": null,
        "dept_id": null,
        "feb": null,
        "id": null,
        "jan": 30,
        "note": null,
        "total_cost": null,
        "updated_at": null,
        "year_id": null
    },
    {
        "acc_ext_id": "41260-02600",
        "cat_code": 10002,
        "cat_ds": "REVENUE",
        "category_id": 2,
        "chart_id": 2373,
        "created_at": "2013-01-15 16:43:52.169213",
        "dept_id": 86,
        "feb": 45,
        "id": 3,
        "jan": 60,
        "note": "Two",
        "total_cost": 105,
        "updated_at": "2013-01-15 16:43:52.169213",
        "year_id": 1
    }
]
Run Code Online (Sandbox Code Playgroud)

然后我尝试迭代对象并对值求和:

var jan;

for (var i=0;i<data.length;i++){ 
    if(data[i].jan != null){    
        jan += parseFloat(data[i].jan); …
Run Code Online (Sandbox Code Playgroud)

javascript

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×1