I have simple code
sites_from_session = 12;
function function_name () {
var items_to_send = sites_from_session;
var template_name = jQuery('#new-site-template-name').val();
console.log(sites_from_session);
items_to_send.push(template_name);
console.log(sites_from_session);
}
function_name();
function_name();
function_name();
function_name();
function_name();
function_name();//...
The problem is that the push method pushes value to both arrays

Where i am wrong?
Arrays do not self clone in JavaScript. When you say something like
where both
arr2is a valid array, you haven’t made an actual copy ofarr2. All you’ve done is create a reference pointer to it forarr1. So when you make a change likeyou are (in essence) saying the same thing as
To properly clone a separate copy you need to use this:
This will return a new array that holds all of the items from the original array.