I was interested to learn about the differences between Grep and Filter:
Filter:
Reduce the set of matched elements to those that match the selector or perform a function test.
Grep:
Finds array elements that satisfy the filter function. The original array is not affected.
OK.
so if i do this in grep:
var arr = [ 1, 9, 3, 8, 6, 1, 5, 9, 4, 7, 3, 8, 6, 9, 1 ]; myNewArray= jQuery.grep(arr, function(n, i){ return (n != 5 && i > 4); });
I could also:
var arr = [ 1, 9, 3, 8, 6, 1, 5, 9, 4, 7, 3, 8, 6, 9, 1 ]; myNewArray= $(arr).filter( function(n, i){ return (n != 5 && i > 4); });
In both situations, I can still access the original array ...
so ... where is the difference?
jquery filter
Royi Namir Apr 13 '12 at 11:25 2012-04-13 11:25
source share