Array里面没有sum的内置对象方法,现下添加一个
<script> Array.prototype.sum=function(){ var sum=0; for(var i=0;i<this.length;i++){ sum=sum+this[i] } return sum } console.log(Array.prototype) var arr=[1,3,5,7]; console.log(arr.sum()) </script>
标签:内置,对象,sum,原型,var,Array From: https://www.cnblogs.com/hs20011205/p/17012971.html