我想对数组中的所有浮点数求和。
当我在Chrome控制台中执行此操作时
$("tr.project_hours").find("td.number").map(function(i,v)
{return parseFloat($(v).attr("data-time"))
})
我理解了。
[0, 0, 0, 0, 0, 0, 0]
这就是我想要的
但是,在我的代码中我有更多的$("tr.project_hours"),我想要单独对它们进行求和。所以,我执行:
$("tr.project_hours").each(function(){
row = $(this).find('td.total')
row.html(sumInputsIn($(this).find("td.number").map(function(i,v){
return parseFloat($(v).attr("data-time"))})));
})
('td.total')是应该显示结果的列。问题是最后的代码在控制台中返回了这个
[0, 0, 0, 0, 0, 0, 0, prevObject: jQuery.fn.jQuery.init[7], context: <tr>]
结果是臭名昭著的NaN(not a number)。
为什么我的数组中会有prevObject?我该如何重构以摆脱它?