Efficient Array Manipulation Splice Removal in JavaScript

Explore our JavaScript category, where you’ll find loads of helpful articles and tutorials for everyone, whether you’re just starting out or a pro developer. Learn about different JavaScript functions that can be used in various projects according to their specific requirements.
This JavaScript code demonstrates the use of the splice method to remove elements from an array.
<script>
// Create an array called splArray with three elements
var splArray = ["St1", "St2", "st3"];
// Log the original array to the console
console.log(splArray);
// Use the splice method to remove elements from index 0 up to (but not including) index 2
splArray.splice(0, 2);
// Log the modified array to the console
console.log(splArray);
</script>

Let's go step by step:

["St1", "St2", "st3"] // Original array
["st3"] // Modified array after using splice