As I understand this, you’re trying to make a deep copy of arrays into client, on button click. If so, for primitive types, you could do this:
var client = [];
var arrays = [1, 2, 3, 4, 5];
function deepCopyPrimitiveValuesInArray() {
client = arrays.slice(0);
// client = arrays.slice(); // this works too
}
var button = document.getElementById('button');
button.addEventListener('click', deepCopyPrimitiveValuesInArray, false);
If your arrays array contains complex types, things get a little complicated… For simplicity I’d recommend:
Functions and DOM nodes are not cloned. The enumerable properties of arguments objects and objects created by constructors other than Object are cloned to plain Object objects.
jQuery’s [deep] extend
On a deep extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not.