7 Replies Latest reply on Jun 13, 2016 9:19 AM by gkaiseril

    Looping through arrays and assigning values

    alexh90310518 Level 1


      I'm using a document level array with 16 elements to hold values, each of these values corresponds to a text field.

      What I am wanting to do is create 2 arrays, one storing the values and one storing the field names themselves in the correct order.

      eg element 0 of both arrays correspond to the text field and it's stored value.


      I want to know if I can loop through both of these arrays and set the values in one sweep rather than writing;

      var txt01 = this.getField("Text1");
      var txt02 = this.getField("Text2");
      //... Etc
      txt01.value = arrTextVal[0];
      txt02.value = arrTextVal[1];
      //... Etc

      Could I write something more along the lines of;

      for (var i in arrTextVal && arrTextName) {
           arrTextName[i].value = arrTextVal[i];

      I realise this may be completely wrong but I'm trying to give a clear example if what I'm trying to achieve.

      Any help is much appreciated.

      Thank you in advance.