Javascript Array to String





7
Date Submitted Sun. Oct. 8th, 2006 9:28 PM
Revision 1 of 1
Beginner trevis
Tags Array | JavaScript | setTimeout | String
Comments 3 comments
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 + ")");
}
 

Trevis Rouse

Comments

Comments Escape
Sat. Oct. 28th, 2006 4:23 PM    Scripter SCoon
Comments Doesn't seem necessary
Tue. Oct. 10th, 2006 8:34 PM    Beginner drench
Comments Why?
Mon. Oct. 9th, 2006 1:20 AM    Newbie phatcat

Voting