0

I am trying to convert my List of Doubles in EL to a Array in JavaScript for use further on with Google Charts.

But i am stuck here in the snippet it sees the var prices as an array of Characters.

    <head>

    ${requestScope.prices} <!-- gives [130.98, 130.84, 133.23, 130.32] -->

<p id="demo"></p>

<script type='text/javascript'>
    var prices = "${requestScope.prices}";
    document.getElementById("demo").innerHTML = prices[2]; //Gives 3

</script>
</head>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • How exactly should the resulting JavaScript code look like? Just rewrite JSP code in such way that it produces exactly the desired JavaScript code. – BalusC Feb 05 '17 at 20:53

1 Answers1

0

You can try it using JSTL. Firstly, fill js array this like and access it.

var prices = [
              <c:forEach var="price" items="${prices}"> 
                <c:out value="${price}" />,            
              </c:forEach>  
             ]; 

document.getElementById("demo").innerHTML = prices[2];
Gurkan Yesilyurt
  • 2,635
  • 2
  • 20
  • 21