title: Javascript for split the string and loop to get to character
body: <p>I have a string something like the below one which gets populated into a text field after looping through the grid from grid one ,1 | xxx,2 | yyy,3 | zzz,4| ,5 |</p>
  
  <p>it is model, Index | Model, index | .... where if nothing is there its blank.
  Now I want logic to get only model and check that against index value and set the model in another grid 2 cell values. </p>
  
  <p>Below is my current code which is very lengthy:</p>
  
  <pre><code>test() {
      alert(Moment);
      var totalSize = fieldname.getGridSize();
      //var getModel =       fieldname.getValue();
      var getModel = document.getElementById("Desktfieldname").value;
  
  
      if (getModel &amp;&amp; getModel != '') {
  
          var res = getModel.split("|");
          alert(res);
          var model1 = res[0];
          var model2 = res[1];
          var model3 = res[2];
          var model4 = res[3];
          var model5 = res[4];
  
          if (model1 != '') {
              var res1 = model1.split(",");
              alert(res1);
              var modelfinal1 = res1[0];
              var indexfinal1 = res1[1];
          }
  
          if (model2 != '') {
              var res2 = model2.split(",");
              alert(res2);
              var modelfinal2 = res2[0];
              var indexfinal2 = res2[1];
          }
  
  
          if (model3 != '') {
              var res3 = model3.split(",");
              alert(res3);
              var modelfinal3 = res3[0];
              var indexfinal3 = res3[1];
          }
  
          if (model4 != '') {
              var res4 = model4.split(",")
              var modelfinal4 = res4[0];
              var indexfinal4 = res4[1];
          }
  
          if (model5 != '') {
              var res5 = model5.split(",")
              var modelfinal5 = res5[0];
              var indexfinal5 = res5[1];
  
              for (var s = 1; s &lt;= totalSize; s++) {
                  var cellValIndex = Index.getCellValue(s);
                  alert(cellValIndex);
                  alert(modelfinal1);
                  if (cellValIndex &amp;&amp; cellValIndex != '') {
                      if (cellValIndex == modelfinal1) {
                          expr = 'feildName.setCellValue         (' + s + ",'" + indexfinal1 + "')";
                          eval(expr);
                      }
  
                  }
  
              }
  
          }
      }
  }
  </code></pre>