8 Replies Latest reply on Dec 23, 2015 2:41 AM by Iain Robinson

    [JS] problem with removing entries from an array

    Iain Robinson Level 1

      Hi all


      Using ID CS5 and I have an array of all the paragraphs in my document that I want to examine and I am having problem removing items from it. I want to remove any paras styled using particular para styles and after that I am going to use some established code to do some other stuff. The other (established) stuff works well but the code to remove certain paragraphs is not working as expected.


      My code;

      app.findGrepPreferences = null;
      app.changeGrepPreferences = null;
      app.findChangeGrepOptions.includeMasterPages = false;
      app.findChangeGrepOptions.includeLockedLayersForFind = false;
      app.findGrepPreferences.findWhat = "^.+$";
      f = app.activeDocument.findGrep ();
      //first goes through array deleting any para styled as "B Head" or "C Head"
      for (i = 0; i < f.length; i++) {
        if (f[i].appliedParagraphStyle.name == "B Head"||f[i].appliedParagraphStyle.name == "C head") 
        f.splice(i, 1);

      If I create a test document with 10 or 12 paras and add in two consecutive headings the code above will only remove the first one. Non-consecutive paras are removed as expected but I don't know what I have done wrong with the loop that uses splice to remove part of it.


      Can anyone advise please?