I discovered a workaround - by directly accessing the original array variable, I was able to achieve the desired result. Despite this, I am still intrigued by the reason behind this behavior.
var array = ["hello"];
var testObject = {arr: array};
testObject.arr = [];
console.log(array) still shows ["hello"] instead of [] as anticipated.
Nevertheless, this approach DOES successfully clear the array
while (testObject.arr.length > 0) {
testObject.arr.splice(0, 1);
}
console.log(array) now displays [] as expected.
Could someone elucidate what is happening here? Thank you!
Additionally, when I run testObject.arr.push("testing"), it behaves as expected....
I am puzzled as to why trying to reassign the array does not work.