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?

More than 3 years have passed since last update.

【JavaScript】配列の一部だけを合計して新しい配列を作る

Last updated at Posted at 2020-04-17

変換前の配列:array1 = [ 年, 月, 日, 人数1, 人数2, ... , 人数47 ];
変換後の配列:array2 = [ 年, 月, 日, 人数1~人数47の合計 ];

つまり、人数を合計したい。

let array2 = array1.slice(0, 3).concat(array1.slice(3).reduce((a, x) => { return a + x }));
0
0
0

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?