JavaScript文字列slice
replaceAll

slice文字列

split

文字列の一部を抽出して新しい文字列を返します。

構文

str.slice(beginIndex, endIndex?)

使用例

下記の値を入力するとサンプルに即時反映されます。

const
arr
console
slice
const arr = [1, 2, 3, 4, 5];
console.log(arr.slice(1, 3));    // [2, 3]
console.log(arr.slice(-2));      // [4, 5]