+ Start a Discussion

Iterating Apex array in javascript

Hi All,

I had this req in my current project. I 've an array which is built in Apex controller.

Say, Integer[] a;

i have values like a[0]=11; a[1]=90; a[2]=45; .........so on.

Now, i want to iterate this array from javascript function.

I tried something like this:


<script type="text/javascript">


  for(var i=0;i<20;i++){

       var v="{!pwL.a[i]}";        // PROBLEM OCCURS HERE. IT IS CONSIDERING " i " as "i" only. but not like an integer, i=0,1,2....so on






Now, in the above snippet, i had an object pwL which consists of array "a".

Now, if i want to iterate through the array, it is throwing me an error as UNKNOWN PROPERTY i.

Seems, it is not able to interpret that   var v="{!pwL.a[i]}";   means  var v="{!pwL.a[0]}";   when i=0.

I want to pass the "i" value and get the value in that array with this index.


Hope, i made you clear!

Please help me out!



Bhawani SharmaBhawani Sharma

Try with this:


<apex:repeat value="{!ListName}" val="item">




Thanks a lot for ur reply!


I am trying to loop through an array, not a list.

I believe apex:repeat can't handle array :(


Hey, I am really sorry. I did not understand earlier.

I tried working in the way u mentioned. It worked perfectly.

This is how i implemented:


<apex:repeat value="{!pwL.a}" var="asdasd">





Thanks a lot for your help.


May be this is what you want.