2 Replies Latest reply on Feb 16, 2015 2:46 AM by lindaeliseruble

    .indexOf and finding an item in an Array

    lindaeliseruble Level 1


      I've been trying to search a PDF page with the following numbers on it:

       

      7.4% 0.1% 0.0% 0.4% 9.7% 0.1% 53.1% 0.5% 0.1% 15.5% 4.8% 1.6% 5.7% 1.0%

       

      I am searching for an item in an array by using .indexOf but have not been successful.

       

      I tried the following code:

       

       

      var srchIndxArr = [7.4,0.1,0.1,0.4,9.7,0.1,0.0,53.1,0.5,0.1,15.5,4.8,0.0,1.6,5.7,1.0];

         srchIndxArr.push(global.index);       

        for (var m in srchIndxArr) {

           if (srchIndxArr.indexOf(global.index)!=-1) {

           console.println("Hello!");

           } else {

           console.println("Bye!");

           }

       

        }

       

      I would appreciate any help.  I'm sure there is a problem with the syntax and/or logic.

       

      Thanks

       

      L.

        • 1. Re: .indexOf and finding an item in an Array
          lindaeliseruble Level 1

          I would like to describe what I am trying to do with this code.

           

          I Have a PDF with a list of numbers that I am searching.  There is a number in the list of numbers that appears more than once.  It is the number 0.1 and it appears four times in the list.  The problem is that I do not want to count the same number twice so I thought that I would also compare the index of the word by creating an array of these word indexes as I am searching the words,. Each time I search a word, I add another index to the array. Then Ithe next word I search will also compare the index number of the current word I am searching with the growing array of word indexes.

           

          i thought I would use ".indexOf" to search for the current word index in the array of indexes that would in turn add that current index to the array for the next number to be searched in the list.

           

          iif you need fiuether clarification, please let me know.

           

          thank you

           

          Linda

          • 2. Re: .indexOf and finding an item in an Array
            lindaeliseruble Level 1

            When I say that I do not want to count the same number twice, I mean I do not want to count the same instance of the number.  That is why I want to compare the index of the number. By comparing the index of the number, this makes each number unique.

             

            thanls

             

            LInda