Correct way to clear contents of an Array in JavaScript
JavaScript
var
// creating an array
myArray = ["lorem", "ipsum", "dolor", "sit", "amet"],
// creating a variable that refers to the previous array.
referenceToMyArray = myArray;
// Printing contents of original arrays.
document.write("Original Array: [" + myArray.join(", ") + "]");
document.write("<br />Reference Variable: [" + referenceToMyArray.join(", ") + "]");
// Clearing the original array
document.write("<br />["+myArray.splice(0, myArray.length).join(", ")+"]");
// Checking the contents of the reference array and original array;
document.write("<br /> <br />Cleared Original Array: [" + myArray.join(", ") + "]");
document.write("<br />Affected Reference Variable: [" + referenceToMyArray.join(", ") + "]");