1
1

More than 1 year has passed since last update.

【JavaScript】【Jquery】カンマ区切りの文字列を配列にする splitを使う

Last updated at Posted at 2023-07-26
process.stdin.resume();
process.stdin.setEncoding('utf8');

let str1 = '1,2,3';
console.log(String(str1).split(','));

let str2 = '1';
console.log(String(str2).split(','));

// ⇓数値型だとエラー
let str3 = 1;
console.log(str3.split(','));

結果

[ '1', '2', '3' ]
[ '1' ]
エラー
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