0

Hi I would like to find a condition in jquery to be sure that the id of the data found by .grep is different from all the values from a vector, with something like this :

var matchedAgainstBrand = $.grep(prodata, function(v,i) {
    return v['id'] !== matchedProIds ;
});

or this

var matchedAgainstBrand = $.grep(prodata, function(v,i) {
    return $.inArray( v['id'], matchedProIds ) == -1;
});

(but these two do not work !)

where matchedProIds is a vector of integers, defined like this :

var matchedProIds = [];
for (i=0; i< matchedPro.length; i++) {
     matchedProIds.push(matchedPro[i]['id']);
}

Can you help with a condition that (un)match a value against a vector ?

3
  • 1
    You want us to write it for you? Commented Jun 3, 2014 at 18:52
  • @JonathanM mmmhh yes !? Commented Jun 3, 2014 at 18:53
  • 2
    Array.indexOf? Commented Jun 3, 2014 at 18:56

1 Answer 1

1

Thanks to the suggestion from @Matt Burland :

var matchedAgainstBrand = $.grep(prodata, function(v,i) {
    return matchedProIds.indexOf(v['id']) == -1;
});
Sign up to request clarification or add additional context in comments.

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.