javascriptasp-classic

Pass a classic ASP session variable array to client side JavaScript?


I have a session variable which is an array of integers, for example:

myArray{1,4,3,5,6,7,9,2,...n}

What I am trying to do is pass this in a session var <%=Session("myArray")%> to my client side JavaScript. I can do it if I take the session var and convert it to a string like this:

    var b = '<%=Session("myArray")%>';
    var bob = new Array();
    bob = b.split(',');

I am just wondering if there is a more direct way of passing the array possibly cutting out the need to convert it to a string before passing so I can just pass it as an array?

Thanks


Solution

  • This should work just fine:

    var bob = [<%=Join(Session("myArray"), ", ")%>];