Is it possible to pass data this way

Is it possible and how to pass data this way?

var client = [];
var arrays = [1, 2, 3, 4, 5];

function passArray() {

function getArray(a) {
	this.a = a;
	if (client.length < 5) {

function retrieveArray(i) {
  	this.i = i;

var button = document.getElementById('button');
button.addEventListener('click', passArray, false);

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:

Things to be aware of:

Lo-Dash’s cloneDeep

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.

Thanks, it works, and thanks for additional info.