You want to use slice() (MDN docu) and not splice() (MDN docu)!

ArrayB = ArrayA.slice(0);

slice() leaves the original array untouched and just creates a copy.

splice() on the other hand just modifies the original array by inserting or deleting elements.

Answer from Sirko on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_splice.asp
JavaScript Array splice() Method
// Create an Array const fruits = ["Banana", "Orange", "Apple", "Mango"]; // At position 2, add "Lemon" and "Kiwi": fruits.splice(2, 0, "Lemon", "Kiwi"); Try it Yourself » · More Examples Below ! The splice() method adds and/or removes array elements. The splice() method overwrites the original array.
🌐
Reddit
reddit.com › r/vuejs › is array.splice(0, array.length) the only way to empty a reactive array in vue 3?
r/vuejs on Reddit: Is array.splice(0, array.length) the only way to empty a reactive array in vue 3?
November 17, 2022 -

Pretty much what the title says. My brain is a bit fried rn, but I believe I could only figure out how to empty a reactive array (i.e. const array = reactive([]);) by doing array.splice(0, array.length);. Is this the way you have to do it? Or is there other ways?

🌐
Metana
metana.io › metana: coding bootcamp | software, web3 & cyber › full-stack › javascript array splice() method - metana
JavaScript Array Splice() Method - Metana
November 10, 2024 - Yes, array.splice(start, 0, item1, item2, …) adds elements without removing any, starting at the specified index.
🌐
Medium
medium.com › @ryan_forrester_ › javascripts-splice-method-a-complete-guide-c579ff14af7a
JavaScript’s splice() Method: A Complete Guide | by ryan | Medium
November 19, 2024 - Remember these key points: - splice() modifies the original array - It returns removed elements as an array - You can remove and add elements in a single operation - Negative indices work from the end of the array · class Carousel { constructor(items) { this.items = items; this.currentIndex = 0; } rotate(direction) { if (direction === 'left') { // Remove from start and add to end const [removed] = this.items.splice(0, 1); this.items.splice(this.items.length, 0, removed); } else { // Remove from end and add to start const [removed] = this.items.splice(-1, 1); this.items.splice(0, 0, removed);
🌐
PHP
php.net › manual › en › function.array-splice.php
PHP: array_splice - Manual
Performing the following functions in a 100,000-iteration loop gave me the following times: ($b is a 3-element array) array_splice($b, count($b)) => 0.410652 $b = array_splice($b, 0) => 0.272513 array_splice($b, 3) => 0.26529 $b = array_merge($b) => 0.233582 $b = array_values($b) => 0.151298 ... Ever wounder what array_splice is doing to your references, then try this little script and see the output.
Find elsewhere
🌐
DhiWise
dhiwise.com › post › javascript-array-splice-method-a-detailed-exploration
JavaScript Array Splice Method: A Comprehensive Guide
September 5, 2024 - The splice method returns an array containing the removed elements. If no elements are removed, it returns an empty array. Negative indices count from the end of the array. If deleteCount is omitted or set to 0, no elements are removed.
🌐
ReplayBird Blog
blog.replaybird.com › javascript-array-splice
How to Use JavaScript Array splice() Method? - ReplayBird
June 20, 2024 - Finally, we will look into how to remove all the elements of the array In JavaScript, the splice() method efficiently removes all elements from an array by specifying the start index as 0 and omitting the delete count parameter.
🌐
O'Reilly
oreilly.com › library › view › javascript-the-definitive › 0596101996 › re16.html
Array.splice( ): insert, remove, or replace array elements — ECMAScript v3 - JavaScript: The Definitive Guide, 5th Edition [Book]
August 17, 2006 - An array containing the elements, if any, deleted from array. splice( ) deletes zero or more array elements starting with and including the element start and replaces them with zero or more values specified in the argument list.
Author   David Flanagan
Published   2006
Pages   1018
🌐
DEV Community
dev.to › swarnaliroy94 › array-splice-array-slice-ag
Array.splice() & Array.slice() - DEV Community
August 18, 2021 - 🔸 If no element is specified, splice() will only remove elements from the array. Let's move on to some examples to understand this concept better. We need to always remember that index of an array starts at 0.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › toSpliced
Array.prototype.toSpliced() - JavaScript | MDN
If skipCount is omitted, or if its value is greater than or equal to the number of elements after the position specified by start, then all the elements from start to the end of the array will be deleted. However, if you wish to pass any itemN parameter, you should pass Infinity as skipCount to delete all elements after start, because an explicit undefined gets converted to 0.
🌐
p5.js
p5js.org › reference › p5 › splice
splice
The third parameter is an index value which specifies the array position from which to insert data. (Remember that array index numbering starts at zero, so the first position is 0...
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.splice()
JavaScript Array splice(): Delete, Insert, and Replace Elements
November 6, 2024 - ... The start argument specifies the starting position in the original array in which the new elements will be inserted. The second argument is zero (0) that instructs the splice() method not to delete any array elements.
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript array splice method
JavaScript Array Splice Method
September 1, 2008 - Learn how to use the JavaScript Array splice() method to add or remove elements from an array. Explore examples and syntax for effective coding.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › splice
JavaScript Array splice() - Modify Array Elements | Vultr Docs
December 6, 2024 - ... Look at the following basic ... Understand how to insert elements without removing any existing elements. Use splice() with deleteCount set to 0....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-array-splice-method
JavaScript Array splice() Method - GeeksforGeeks
If omitted, all elements from startIndex to the end are removed. If set to 0, no elements are removed. item1, item2, ..., itemN: Elements to add starting at startIndex. If none are provided, splice...
Published   May 24, 2025
🌐
Favtutor
favtutor.com › articles › array-splice-javascript
JavaScript Array splice() Method (with Examples)
November 11, 2023 - To add elements at the end of an array using the splice() method, you need to provide the starting index as the length of the array and the number of elements to remove as 0.