Javascript sliceを使用して先頭から指定した数の文字列を削除する

環境
Google Chrome 111.0.5563.147
Windows 10 Home 64bit

構文
文字列str.slice(数値);
sliceメソッドを使って、先頭から指定した数の文字列を削除します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let str = "テストデータ";
//先頭3文字を削除
let result = str.slice(3);
console.log(result);
let str = "テストデータ"; //先頭3文字を削除 let result = str.slice(3); console.log(result);
let str = "テストデータ";

//先頭3文字を削除
let result = str.slice(3);
console.log(result); 

結果
> “データ"

JavaScript

Posted by arkgame