Using eval() in Javascript to unpack the array
        Posted  
        
            by gnomixa
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by gnomixa
        
        
        
        Published on 2010-05-25T22:00:17Z
        Indexed on 
            2010/05/25
            22:51 UTC
        
        
        Read the original article
        Hit count: 308
        
JavaScript
|eval
I have an array that I need to unpack.
So, from something like
var params = new Array();
params.push("var1");
params.push("var2");
I need to have something like
"var1", "var2".
I tried using eval, but eval() gives me something like var1, var2...i don't want to insert quotes myself as the vars passed can be integers, or other types. I need to pass this to a function, so that's why i can't just traverse the array and shove it into a string.
What is the preferred solution here?
© Stack Overflow or respective owner