_以降の文字列を取得

テキスト処理文字列

 閲覧数:370  投稿日:2020-02-25  更新日:2020-02-25  

_以降の文字列を取得
※_は、指定文字列内で1回のみ使用されていることが前提

考え方
・_を区切り文字として配列へ格納
・最後の文字列を取得


コード

const str = 'url_9'
const strSpilitAry = str.split("_"); //_を区切り文字として配列へ分割
const resultStr = strSpilitAry[strSpilitAry.length - 1]; //配列の最後
console.log(resultStr); //9



結果

9



タグ


spilit 



spilitで、指定した内容で分割できないときの戻り値は、["対象文字列"]



週間人気ページランキング / 6-30 → 7-6
順位 ページタイトル抜粋 アクセス数
1 JavaScriptコード 11
2 ログイン 2
2026/7/7 5:05 更新