728x90
✨ Array의 특정 index를 지정하여 제거하거나 삽입할 수 있는 build-in method
💻Example Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = ['one', 'three', 'five']; | |
arr.splice(1, 0, 'two'); | |
console.log(arr); | |
arr.splice(3, 1, 'four'); | |
console.log(arr); | |
arr.splice(0); | |
console.log(arr); |

🧨 splice(시작 index, option, 값) 의 형식으로 사용할 수 있으며,
option에 0을 지정하면 삽입, 1을 지정하면 제거(변경) 효과를 볼 수 있다.
또한, splice(0)을 이용하면 해당 array의 모든 값을 제거하는 효과를 볼 수 있다.
👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
Array.prototype.splice()
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
developer.mozilla.org
'JavaScript > Built-in Method etc.' 카테고리의 다른 글
String.prototype.trim() (2) | 2020.08.10 |
---|---|
Array.prototype.find() (0) | 2020.06.09 |
String.prototype.charAt() (0) | 2020.02.22 |
Set (Object) (0) | 2020.02.20 |
String.prototype.localeCompare() (0) | 2020.02.20 |