0
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

3

2 Answers 2

5

Use Array.filter

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];
var filtered = myFind_collections.filter(
                  function(a){return pgRangeCollection.indexOf(a) < 0}
               ); // => [ 3, 6, 10 ]

See also (filter) and also (indexOf)

Sign up to request clarification or add additional context in comments.

3 Comments

myFind_collections.filter is not a function
Read the articles from the links in my answer, especially the Polyfill section
Are you testing on a version of IE < 9 ? Because it is not implemented in this so called browser versions
0

The answer should be using the .filter method as already proposed by KooiInc but since IE is a requirement I would use the difference method of Lodash or Underscore:

_.difference(myFind_collections, pgRangeCollection) // [3,6,10]

Just include it via cdn: http://cdnjs.com/libraries/lodash.js/

or if you already have jQuery:

 $(myFind_collections).not(pgRangeCollection).get() // [3,6,10]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.