Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to remove set of item values of array from another array in Javascript

New Here ,
Feb 26, 2014 Feb 26, 2014

var myFind_collections =[3,6,10,234,235,236,237,238,239,240,241,244,245,246,247,248,248,249,250];var pgRangeCollection = [234,235,236,237,238,239,240,241,244,245,246,247,248,248,249,250];for(v=0;v<=pgRangeCollection.length;v++){    var pgMatch = pgRangeCollection[v];    clear_pg_range(pgMatch);    }function clear_pg_range(pgMatch){        //for(d=0;d<=myFind_collections.length-1;d++){        for(d=0;d<=myFind_collections.length-1;d++){            var docFound = parseInt(myFind_collections[d]);            if(pgMatch===docFound){                    myFind_collections.splice(myFind_collections[d],1);                    alert(docFound + " was removed");                }            }    }alert(myFind_collections.length);

in above code i want to remove every item in myFind_collections which equals to pgRangeCollection

i want the output as (3,6,10) but i am getting the output as (248,249,250)

i dont know where i mistaking can anybody suggest solution for this,

Thanks in advance

TOPICS
Scripting
958
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2014 Feb 26, 2014

@Vimal – this is the wrong forum for questions like that (ExtendScript scripting). There is a dedicated forum here around:

http://forums.adobe.com/community/indesign/indesign_scripting?view=discussions

But before someone is moving this thread over, let me ask you some questions:

1. Why is page number 248 a double entry in both arrays at the start of your script?

2. Do you want to make all numbers unique?

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2014 Feb 26, 2014

Now moved to the scripting forum....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2014 Feb 26, 2014

If you don't mind "borrowing" code from someone else, this might be interesting for you:

by Vivekanand.K

http://www.developersnippets.com/about/

http://www.developersnippets.com/2009/05/29/comparing-two-arrays-and-removing-duplicates-from-origin...

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2014 Feb 26, 2014
LATEST

Vimal,

You were very close, the only problem is that you got .splice() wrong. Instead of

myFind_collections.splice(myFind_collections,1)

use

myFind_collections.splice(d,1)

The first argument of splice() is a position, not some content.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines