実際にどう使われますか?
下の例文を通して、それぞれの単語がどのような状況で使われるのか学んでみましょう!
unshift
例文
You can use the unshift method to add a new element to the beginning of the array. [unshift: verb]
unshift メソッドを使用すると、配列の先頭に新しい要素を追加できます。[シフト解除:動詞]
例文
The unshift operation is used to insert an element at the beginning of the queue. [unshift: noun]
シフト解除操作は、キューの先頭に要素を挿入するために使用されます。[シフト解除:名詞]
prepend
例文
You can use the prepend function to add a new character to the beginning of the string. [prepend: verb]
prepend 関数を使用すると、文字列の先頭に新しい文字を追加できます。[先頭に: 動詞]
例文
The prepend operation is used to insert an element at the beginning of the sequence. [prepend: noun]
prepend 操作は、シーケンスの先頭に要素を挿入するために使用されます。[先頭に: 名詞]
追加で知っておくといいこと
どっちの方がよく使われますか?
Unshiftは、特に配列を操作する場合に、プログラミング言語でprependよりも一般的に使用されます。ただし、prependは、文字列の先頭に文字を追加したり、リンクリストの前に要素を追加したりするのに便利な方法です。
どっちの方がよりフォーマルですか?
unshiftとprependはどちらもプログラミングで使用される技術用語であるため、一般的に形式言語と見なされます。