The issue here is that javascript passes objects around by reference.
This line of code
window.g_a_PreEditData = aData;
does not create a copy
of the object and assign it. It instead assigns a reference.
In other words, after this call, window.g_a_PreEditData
and aData
are pointing to the same one object.
If this isn't what you want, you will have to clone aData
. Since aData
is an array, you can do this via the slice
method.
window.g_a_PreEditData = aData.slice();
If aData
was an object you would have to clone it some other way. See this question on the topic of cloning objects in javascript.