Question

I'm creating multidimensional arrays with JSTL which should be:

[ ['2013-03',22434.0],['2013-04',11234.0],['2013-05',17434.0] ]

And while doing this with JSTL, I white code like this:

var arrayz = new Array(${list.size()});
<c:forEach var="item" items="${list}" varStatus="s">
  arrayz[${s.index}] = new Array(["'" + "${item.date}".substring(0,7) + "'", ${item.price}]);
</c:forEach>
console.log("arrayz: " + arrayz);

In the console it turns out to be :

arrayz: '2013-03',22434.3,'2013-04',11234.1,'2013-05',17425

How to fix it?

Was it helpful?

Solution

Your array is fine your just seeing the output as a string, try just logging the array by itself

console.log(arrayz);

also might I suggest some simplification of your jstl.

var arrayz = [
<c:forEach var="item" items="${list}" varStatus="s">
    ["'" + "${item.date}".substring(0,7) + "'", ${item.price}]${!s.last?',':''}
</c:forEach>
]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top