title: how to get incremented value in for loop after callback function in javascript?
body: <p>My Requirement:</p>
  
  <p>I want to get the list of values using for loops. In for loop one iteration completed one time then the callback will send that list of values(array). 
     Once the first iteration completed second time  loop value should be  get incremented value.</p>
  
  <p>For example : 5 values
  after 5th iteration then loop is over. then second time loop should start with  '0' but here it's starting with last incremented value. please help me to achieve this.</p>
  
  <p>Below code is working fine for the first time.</p>
  
  <p>Callback function:</p>
  
  <pre><code>$inventoryManagement.getObjectNameAndAttributeAndDataTypeIdUsingObjectAndAttributeId(objectId,attributeId, function(objectAttributeBlockElement) {
      //$scope.val = myOwnJ;
      console.log(objectAttributeBlockElement);
  });
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>var myOwnJ = 0;
  // Getting ObjectId And AttributeId Using CellId For Normal Controls
  var getObjectNameAndAttributeAndDataTypeIdUsingObjectAndAttributeId = function(objectId,attributeId, callback) {
  
      var objectAttributeBlockElement = [];// one array
  
      try {
          // iterate over the objectAttributes
          for (var i = 0; i &lt; pageObject.objects.length; i++) {               
              if (pageObject.objects[i].id == objectId) { 
                  var name = "";
                  var labelName = "";
                  var dataTypeId = "";                    
                  for (;myOwnJ &lt; pageObject.objects[i].objectAttribute.length;) {                 
                      name = pageObject.objects[i].objectAttribute[myOwnJ].name;// got the current label name
                      labelName = pageObject.objects[i].objectAttribute[myOwnJ].labelName;// got the current name
                      dataTypeId = pageObject.objects[i].objectAttribute[myOwnJ].dataTypeId;// got the current dataTypeId
  
                      objectAttributeBlockElement.push(name,labelName,dataTypeId);
                      callback(objectAttributeBlockElement, myOwnJ++);                        
                      return;                         
                  }
              }
          }
          throw {
              message: "objectId not found: " + objectId
          };
      } catch (e) {
          console.log(e.message + " in getObjectNameAndAttributeAndDataTypeIdUsingObjectAndAttributeId");
      }
  };
  </code></pre>