1
1

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のスプレッド構文について

1
Posted at

Reactを学んでいたら、Rubyでも出てきたスプレッド構文が出てきたので、整理するためにまとめました。
スプレッド構文(spread = 広げる・展開する)

#Ruby
array = [1, 2, 3]
new_array = [*array, 4]
# → [1, 2, 3, 4]
# Rubyの ... は範囲を表す
(1...5) # → 1, 2, 3, 4 (5を含まない範囲)
(1..5)  # → 1, 2, 3, 4, 5 (5を含む範囲)
// JavaScript
const array = [1, 2, 3]
const newArray = [...array, 4]
// → [1, 2, 3, 4]
// JavaScriptの * は掛け算くらい
3 * 5 // → 15

ちなみにPythonも*arrayでかくみたいです。

言語 ... の意味 * の意味
JavaScript 展開(スプレッド構文) 掛け算
Ruby 範囲オブジェクト 展開(スプラット演算子)

同じ記号でも言語によって意味が全然違うので混乱しますね...

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?