LoginSignup
1
0

More than 1 year has passed since last update.

Array.someで引数を渡したい

Last updated at Posted at 2022-03-11

javascriptのArray.someで引数を渡して判定したときのメモ。

someを実行する配列がObjectの配列だったりすると、callback関数内での判定の際に複数の値をチェックしたくなると思います。
以下のようにコールバック関数の引数にthisを入れてあげれば、それを使える。

function filterFunc(this:Obj1, element:Obj2){
  //判定処理
}

obj2Array.some(filterFunc, obj1);

MDNには以下のようにあって、thisArgをどうやって使えばよいかわからなかったのでメモ。

thisArg 引数が some() に与えられると、それがコールバックのの this として使用されます。それ以外は、undefined 値が this として使用されるでしょう。 callback が最終的に見ることができる this の値は、関数から見た this の決定に関する一般的なルールによって決定されます。

1
0
1

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
1
0