7 Replies Latest reply on May 29, 2014 5:18 AM by try67

    About use JavaScript to search values in array

    Control1982

      hello every one:)

       

      recently, i started learn the javascript in Acrobat, i have problem, could you help me?

      attach my code

       

      var page=[2,2,2];
      
      
      var Arr = ["Serious Listed Reports - Initial","Non-Serious Unlisted Reports - Initial"];
      
      
      for (var i=0; i<Arr.length; i++) {
      this.pageNum = 0;
      search.query(Arr[i], "ActiveDoc");
      page[i]=this.pageNum;
      
      
      }
      
      
      for (var j=0; j<page.length; j++)
      console.println("Pages: "+page[j]); 
      
      
      Pages: 0
      
      
      
      
      
      
      
      ages: 0
       2
      

       

      the output is

      Pages: 0

      Pages: 0

      Pages: 2

       

      the code meaning is to show the page num which the value in Arr first appear in doc.

      i think the root cause is this ||||  search.query(Arr[i], "ActiveDoc");"   ||||||||

      after the first time in for cycle, the search found the string="Serious Listed Reports - Initial" appear in first page

      but

      in second time in for cycle, the search function can not search a new string, am i right?

      Well, are there other ways can solve this problem?

       

      many thanks in advance~~~~