![](/img/trans.png)
[英]Not getting data from api into the web page, can anyone help me through this where I am getting an error and what can i do to get data
[英]Reduce function execution - Can anyone help me in identifying the error as I am unable get the result
const sum = (arr) => { arr.reduce((acc, val) => { return acc = acc + val; }, 0); }; console.log(sum([2, 3, 4, 5]));
您必須在sum
方法中返回調用結果以reduce
。
此外,在reduce
方法中,您將返回分配值的結果。 返回分配的結果可能會令人困惑,在這種情況下不需要這樣做。
考慮到所有這些,您的代碼應如下所示:
const sum = arr => arr.reduce((acc, val) => acc + val, 0); console.log(sum([2, 3, 4, 5]));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.