0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Reactでのreduceの使い方

Posted at

はじめに

ReactやJavaScriptでreduceを使おうとして困ったのでまとめます。

問題

記録した勉強の時間を合計した値をみることができるようにしたい。

解決方法

const totalTime = records.reduce((sum, current) => {
    return sum + parseInt(current.time);
  }, 0);

おわりに

変数の定義の仕方等でコードの中身は変わると思いますが、参考になったら嬉しいです。

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?