I am creating an array for a list of markers of google map. The code works for one forEach loop but I need to add elements of a new array to the list as well.
My current code shows following error message on var of result2.
Syntax error on token "var", ; expected
Code for one array
var results = [
<c:forEach var="cus" items="${customer}" varStatus="loop">[
"${cus.value.name}", "${cus.value.latitude}",
"${cus.value.longitude}", "${loop.index}",
"${cus.value.id}"], </c:forEach> ];
Code for two arrays
var results = "[" +
<c:forEach var="cus" items="${customer}" varStatus="loop">[
"${cus.value.name}", "${cus.value.latitude}",
"${cus.value.longitude}", "${loop.index}",
"${cus.value.id}"], </c:forEach>
var results2 = results + <c:forEach var="staff" items="${staff}" varStatus="loop">
+ "[" +
"${staff.value.name}", "${staff.value.latitude}",
"${staff.value.longitude}", "${loop.index}",
"${staff.value.id}"], </c:forEach>
+"]";
First of all, in your code for two arrays you don't want to have square brackets enclosed in the quotation marks. This will make your whole arrays
resultandresult2to be a Strings.Second, closing bracket is missing for
results, opening bracket is missing forresults2.Third, you cannot just
+the arrays in JavaScript. There's aconcat()method for that.Try this: