I need to pass a velocity string array to JavaScript function. So, for that, I want to convert the velocity array into JavaScript array.
The source code looks like this :
String[] arrStr[] = new String[3];
arrStr[0] = "String 1";
arrStr[1] = "String 2";
arrStr[2] = "String 3";
request.setAttribute("a", arrStr);
In my HTML template,
#set ( #arr = $request.getAttribute("a"))
<script language="javascript">
var newArr = "${arr}";
</script>
But the string arrays are not copied to newArr. Can anyone help me out on this ?
Something like:
var newArr = [
#foreach( $var in $arr )#if($foreach.index> 0),#end "$var" #end
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With