Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Probably he used $(arr).each() Commented May 24, 2011 at 9:11
  • 1
    Thanks for this. I was actually looking for a function like inArray and like the function i wrote above that would not make me create a function like you just created. So to make my self clear is there a built in function that does what your function does. But perhaps i'm looking too far. Commented May 24, 2011 at 9:13
  • Yeah. I actually don't like that about jQuery.... the names are all too overloaded. Of course, the other side of that coin is something like PHP with its hundreds of un-namespaced top-level functions. Commented May 24, 2011 at 9:14
  • @Daniel - No, but that's sort of the point of JavaScript. I added an additional example, which shows how to take a core object and extend it through its prototype. Generally, this is a more advanced technique, and definitely prone to its own set of issues because it isn't very atomic. Commented May 24, 2011 at 9:38
  • Hi John, how did you get around this aspect of jQuery.each (taken from jQuery API): "We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration." Commented Nov 9, 2011 at 2:40