I have a piece of code and it does not work as I expected. I have created an Array and I have copied it to a new one. I expected that the 2nd one would not change its value when the 1st one does it, but it seems that it does it. How could I avoid? I would like to print the initial value after pressing "Reset", but the value of aux has changed when the value of arrayStringDates2 changed.
var arrayStringDates2 = ["10/01/2017", "20/01/2018", "16/12/2015"];
var aux = arrayStringDates2;
document.getElementById("arrayStringDates2").innerHTML = arrayStringDates2;
document.addEventListener('click', function(event) {
if (event.target.id == "format2") {
for (i = 0; i < arrayStringDates2.length; i++) {
arrayStringDates2[i] = arrayStringDates2[i].replace(/["/"]/gi, "");
}
document.getElementById("arrayStringDates2").innerHTML = arrayStringDates2;
}
if (event.target.id == "resetFormat") {
console.log(aux)
document.getElementById("arrayStringDates2").innerHTML = aux;
}
}, false);
<button id="format2">
Format
</button>
<button id="resetFormat">
Reset
</button>
<div id="arrayStringDates2"></div>