| filter()メソッド |
| trueを返す要素のみを新しい配列に含めます。 |
| true | 要素は新しい配列に含められます。 |
| false | 要素は新しい配列に含められません。 |
const ary3 = [10, 20, 30, 40, 50]; const removeIndex = 2; //removeIndexに対応する要素を除いた新しい配列を生成します const ary4 = ary3.filter((_, i) => i !== removeIndex); console.log(ary3);//[10, 20, 30, 40, 50] console.log(ary4);//[10, 20, 40, 50]
| _ | filterメソッドは、要素の値とインデックスの両方をコールバック関数に渡します。 しかし、このサンプルでは値は使用しないため`_`で無視しています。 |
| i | 要素のインデックスを表します。 |
| filter() method |
| Only elements that return true will be included in the new array. |
| true | Elements are included in the new array. | |
| false | Elements are not included in the new array. |
const ary3 = [10, 20, 30, 40, 50]; const removeIndex = 2; //Creates a new array without the element corresponding to removeIndex. const ary4 = ary3.filter((_, i) => i !== removeIndex); console.log(ary3);//[10, 20, 30, 40, 50] console.log(ary4);//[10, 20, 40, 50]
| _ | The filter method passes both the element's value and index to the callback function. However, since the value is not used in this example, it is ignored with `_`. |
| i | Represents the element's index. |
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |