How to remove set of item values of array from another array in Javascript
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
@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
Copy link to clipboard
Copied
Now moved to the scripting forum....
Copy link to clipboard
Copied
If you don't mind "borrowing" code from someone else, this might be interesting for you:
by Vivekanand.K
http://www.developersnippets.com/about/
Uwe
Copy link to clipboard
Copied
Vimal,
You were very close, the only problem is that you got .splice() wrong. Instead of
myFind_collections.splice(myFind_collections
use
myFind_collections.splice(d,1)
The first argument of splice() is a position, not some content.

