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 1 year has passed since last update.

メソッドチェーン

Posted at

メソッドチェーンを使用すれば、変数を取らなくて良なり、簡潔にコードを書くことができる。
メソッドチェーンとはメソッドを呼び出した返り値に対して、さらにメソッド呼び出しを行うこと。チェーンを長くしす
ぎると読みにくくなるので改行するなどして工夫する。

const array = [1, 10, 3, 7, 6, 9, 5, 8, 2, 4]

// 変数を取った場合
const result = array.filter(value => value <= 5)
result.forEach((result) => console.log(result))
// 1 3 5 2 4

// メソッドチェーンを使用した場合
array.filter(value => value <= 5).forEach((numbers) => console.log(numbers))
// 1 3 5 2 4

参考

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?