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

AlphabetAdvent Calendar 2022

Day 19

【S】String.sliceで文字列の一部分を取り出す

Last updated at Posted at 2022-12-18

「一部抜き出すやつなんだっけ……」ってなりすぎです、いい加減学んでください僕

回答

前n文字を消す

String.prototype.slice(n)

slice-1.js
"あいうえお".slice(2) // => "うえお"

後ろn文字だけ残す

String.prototype.slice(-n)

slice-1.js
"あいうえお".slice(-2) // => "えお"

前n文字を残して、更に前m文字を消す

String.prototype.slice(m, n)

slice-1.js
"あいうえお".slice(1, 4) // => "いうえ"

後ろn文字を残して、更に後ろm文字を消す

String.prototype.slice(-n, -m)

slice-1.js
"あいうえお".slice(-4, -2) // => "いう"
1
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
1
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?