Bug Tracker

Opened 9 years ago

Closed 9 years ago

#8878 closed enhancement (invalid)

jquery grep documentation

Reported by: jquery@… Owned by: jquery@…
Priority: low Milestone: 1.next
Component: web Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

Description

the jquery grep page documentation seems to indicate that the original array is modified and does not specify if the function returns an array. The original array is not modified and it returns the result.

var a = [-1,0,1,2];
var b = $.grep( a, function(n,i){
   return n > 0;
 });
console.log(a) // [-1,0,1,2]
console.log(b) // [1,2]

Change History (3)

comment:1 Changed 9 years ago by addyosmani

Component: unfiledweb
Owner: set to jquery@…
Priority: undecidedlow
Status: newpending

From the grep documentation:

Finds the elements of an array which satisfy a filter function. The original array is not affected.

also with respect to your comments on the function returning an array:

invert: If "invert" is false, or not provided, then the function returns an array consisting of all elements for which "callback" returns true. If "invert" is true, then the function returns an array consisting of all elements for which "callback" returns false.

Is there some specific text which you find to be misleading or which could be improved upon?

comment:2 Changed 9 years ago by jquery@…

Status: pendingnew

Sorry I missed that in the documentation. Also, I had remembered seeing someplace the return type of the function and parameters for the callback. And it's in the header, of course I missed that as well for some reason.

(e.g. jQuery.grep( array, function(elementOfArray, indexInArray), [ invert ] ) Returns: Array )

Thanks for your attention to detail that I seem to be lacking today.

To answer your question, and bow out gracelessly, I read "The $.grep() method removes items from an array as necessary..."

Thanks.

comment:3 Changed 9 years ago by timmywil

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.