我試圖計算頁面中幾個元素的高度之和,使用地圖& reduce。不知什麼原因,這是我扔以下異常:
VM52933:2 Uncaught TypeError: $(...).map(...).reduce is not a function(…)
$('.items')
.map((index,slide) => $(slide).height())
.reduce((prev, next) => prev + next, 0)
.MAP返回一個有效的數組:
[48, 48, 48, 75, 48]
如果我做圖分開([48,48,48, 75,48] .reduce(...))它的工作原理。 我在這裏做錯了什麼?
添加'獲得()''的和map''reduce'之間。否則,你有一個包含數組的jQuery對象。 –
你可以在小提琴中用'.items'發表一個小例子嗎? – webdeb
這是因爲['.map'](http://api.jquery.com/map/)方法返回** jQuery對象**,而不是數組。 – hindmost