0 Replies Latest reply on Jul 22, 2015 12:40 PM by lindaeliseruble

    Removing an array item every time code loops without items being added back to array

    lindaeliseruble Level 1



      I am trying to do something that I thought would be relatively simple, however, I'm having some trouble.

      I've created a function and I am using splice() to remove an item from an array of numbers each time the code loops.


      The first time the code loops through, I get what I expect.  An item is located in the array and then it is spliced out of the array as illustrated below:


      Array Items before splice(): 0.3,21.4,0.0,0.0,1.2,10.8,0.4,3.1,2.4,14.7,6.9,0.0,28.3,1.3,7.3,1.8

      Array Items after splice(): 21.4,0.0,0.0,1.2,10.8,0.4,3.1,2.4,14.7,6.9,0.0,28.3,1.3,7.3,1.8


      The "0.3" had been spliced out of the code.  I was hoping to locate the next array item and splice it out of the array items that were left the next time the code goes through the loop, however, this does not happen.  Instead, I wind up with the original set of array items and I am back to square one.


      I realize that each time the function one2oneComp is called, the array is replenished with the original items.  How do I prevent this from happening?

      Below is the function I wrote.  I'm sure one of you Experts will know the answer.


      Thanks in advance.




      function one2oneComp(doc, p, matchTerm, mode, wordsInRect, loopCntr) {
               var results = [];
               var splicedMT = [];

               var z = wordsInRect.indexOf(matchTerm);
               if (z != -1) {

                    results.push({matchTerm: matchTerm, page: p, index: loopCntr});  
                    return results;