Skip to main content

Bug Tracker

Side navigation

#8878 closed enhancement (invalid)

Opened April 14, 2011 07:43PM UTC

Closed April 14, 2011 09:34PM UTC

jquery grep documentation

Reported by: jquery@shanimal.com Owned by: jquery@shanimal.com
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]
Attachments (0)
Change History (3)

Changed April 14, 2011 08:33PM UTC by addyosmani comment:1

component: unfiledweb
owner: → jquery@shanimal.com
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?

Changed April 14, 2011 08:59PM UTC by jquery@shanimal.com comment:2

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.

Changed April 14, 2011 09:34PM UTC by timmywil comment:3

resolution: → invalid
status: newclosed