Javascript Array to String
7
I use this function when passing an array to a function being called from setTimeout();
function arrayToString(arr) {
return str = 'new Array("' + arr.join('", "') + '")';
}
function someFunction(someArray) {
//do whatever here
}
function anotherFunction() {
var myArray = new Array(1, 2, 3, 4, 5, 6, 7);
var arrayString = arrayToString(myArray);
setTimeout("someFunction(" + arrayString + ")");
}






Use following to reproduce defect in your function.
arr[1] = 'Foo " bar';
alert(arrayToString(arr)); // new Array("", "Foo " bar")
setTimeout(function () { my_function(my_arg_array) }, 1000)
It's already done for you. And if you find yourself going through the trouble in the first place you're already doing something wrong.
The only time I've ever done anything close is for XMLHttpResponse Server -> Client ... and even that's a hack IMO.
Yeesh.