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?

文字列.split() の動作(javascript)

Posted at

こんにちは。
javascript の空白文字に関する split(" ")split(/\s+/) を動作確認しました。仕様を確実に理解しないと、間違いやすいと思いました。

# .split(" ")
$ deno eval 'console.log("".split(" "))'
[ "" ]
$ deno eval 'console.log("1".split(" "))'
[ "1" ]
$ deno eval 'console.log("   ".split(" "))'
[ "", "", "", "" ]
# .split(/\s+/)
$ deno eval 'console.log("".split(/\s+/))'
[ "" ]
$ deno eval 'console.log("1".split(/\s+/))'
[ "1" ]
$ deno eval 'console.log("   ".split(/\s+/))'
[ "", "" ]
0
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
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?