瀏覽器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循環,一個一個取出來,放到新建的數組里。