3 Replies Latest reply on Jan 22, 2013 4:04 AM by Jump_Over

    Compare two arrays

    BEGINNER_X Level 3

      Hi All/csm,


      I want to find out the missing folio pages.



      Using Loop and push get the total pages.length 


      var myTotalpages = 10     //Array 1



      Using findText  find out the total found items "Current Page Number (^N)" count (i.e., 8)


      var myTotalFoundItems = 8       //Array 2






      How can i find out the missing folio page number.



      Please can anyone give the solution for me.





        • 1. Re: Compare two arrays
          csm_phil Level 4

          Helllo BEGINNER_X,


          Your request is not clear. anyway find the below.


          In your previous post you still not select choice of "correct answer" or "Helpfull Answer". do this everytime your posting the request.



          var a1 = [1,2,3]
          var a2 = [1,2,3]
          var a1String = a1.toString() // "1,2,3"
          var a2String = a2.toString() // "1,2,3"
          if(a1String == a2String) // true




          • 2. Re: Compare two arrays
            BEGINNER_X Level 3

            Hi csm,


            Previously wrongly posted  without completed my requirement. After that i edit and posted with correct explanation.


            For the .indb program i give "Helpful answer" for you. Kindly check it in your end.



            Thanks in advance


            • 3. Re: Compare two arrays
              Jump_Over Level 5



              If can I suggest something...

              To compare two arrays try to fill them with same kind of data, i.e. page.names

              For Array 1 shouldn't be a problem.

              For Array 2 to you could use:




              From this point you could start to compare which element from Array 1 is missing in Array 2


              To compare 2 arrays you could define array.prototype:

              For example like this:

              Array.prototype.compare = function (array){

                   var mRes = new Array();

                   var check = false;

                   for(var a = 0; a<this.length; a++)


                      for(var b=0; b < array.length; b++)

                          if(array[b] == this[a]) check = true;

                          if (!check)

                        { mRes.push(array[b]); check = false; }


                  return mRes;



              and in your code:

              var Array3 = Array2.compare(Array1);


              Array3 should collect all elements from Array1 which weren't found inside Array2



              1 person found this helpful