Skip to main content
Participant
February 26, 2014
Question

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

  • February 26, 2014
  • 3 replies
  • 1022 views

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

This topic has been closed for replies.

3 replies

Peter Kahrel
Community Expert
Community Expert
February 26, 2014

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.

Community Expert
February 26, 2014
Community Expert
February 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

Peter Spier
Community Expert
Community Expert
February 26, 2014

Now moved to the scripting forum....