正規表現でマッチした部分を取得する
'2024-03-25'.match(/d+/g); // ['2024','03','25'] // matchAll: キャプチャグループも含む for (const m of 'test1 test2'.matchAll(/test(d)/g)) { console.log(m[0], m[1]); // 'test1' '1', ... }
matchAllはイテレータを返すので配列に変換して使う([...str.matchAll(...)])。
split()
replace() / replaceAll()
includes() / startsWith() / endsWith()
trim() / trimStart() / trimEnd()
前の関数
padStart() / padEnd()
次の関数
slice() / substring()