当前位置:编程问答 > JS >

Javascript Firebug为什么显示NaN

问题:计算数组comp312里所有人test的平均数: var comp312 = [ { name: 'Peter', test: 80, exam: 70 }, { name: 'John', test: 60, exam: 65 }, { name: 'Mary', test: 90, exam: 85 }, { name: 'Christine', test: 70, exam: 76 } ]; function average(a){ var sum,num = 0; for(i=0;i<a.length;i++){ sum+=a[i].test; num++; } console.log(sum/num); } average(comp312);
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,