浏览器DevTools的console里输入js执行
var trs = document.querySelectorAll('tr.ng-star-inserted td:nth-child(4)'); var atrs = Array.from ? Array.from(trs) : Array.prototype.slice.call(trs); var nArr = atrs.map(function(i) {return parseInt(i.innerHTML)}); nArr.reduce(function(p, c){return p + c;});
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
Array.from(arrayLike[, mapFn[, thisArg]])
Array.from() 方法有一个可选参数 mapFn,让你可以在最后生成的数组上再执行一次 map 方法后再返回。也就是说 Array.from(obj, mapFn, thisArg) 就相当于 Array.from(obj).map(mapFn, thisArg), 除非创建的不是可用的中间数组。 这对一些数组的子类,如 typed arrays 来说很重要, 因为中间数组的值在调用 map() 时需要是适当的类型。
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
https://www.cnblogs.com/wphl-27/p/10336591.html
Array.prototype.slice就是对该对象使用Array类的slice方法。但是呢arguments它又不是个Array对象,所以我们没法用arguments.slice()方法,这样是会报错的。 所以这里,我们需要使用Array.prototype.slice.call, 它的作用就是第一步把arguments转换为一个Array对象。
方法一 : var args = Array.prototype.slice.call(arguments);
方法二: var args = [].slice.call(arguments);
方法三: 用for循环,一个一个取出来,放到新建的数组里。