JavaScript splice()メソッドで既存の要素を取り除くサンプル

環境
Windows 10 home 64bit
Google Chrome 107.0.5304.122

構文
splice(start, deleteCount)
start
配列を変更する先頭の位置です。
deleteCount
配列の start の位置から取り除く古い要素の個数を示す整数です。
戻り値
取り除かれた要素を含む配列です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const cft = ['study', 'skill', 'become', 'smart', 'sturgeon'];
const res = cft.splice(3, 1);
console.log(res);
console.log(cft);
const cft = ['study', 'skill', 'become', 'smart', 'sturgeon']; const res = cft.splice(3, 1); console.log(res); console.log(cft);
const cft = ['study', 'skill', 'become', 'smart', 'sturgeon'];
const res = cft.splice(3, 1);
console.log(res);
console.log(cft);

実行結果
> Array [“smart"]
> Array [“study", “skill", “become", “sturgeon"]

JavaScript

Posted by arkgame