Skip to main content

Bug Tracker

Side navigation

#13362 closed bug (notabug)

Opened January 31, 2013 07:40PM UTC

Closed January 31, 2013 07:55PM UTC

Last modified February 18, 2013 05:23PM UTC

jQuery.each() used to work on strings, but it doesn't in 1.9

Reported by: gregoryb@ualberta.net Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:
Description

In jQuery 1.8.3 I could use .each() on a string and it would iterate over the characters in that string, but in 1.9 it fails with:

Uncaught TypeError: Cannot use 'in' operator to search for <x> in <y>

Where <x> is an index and <y> is a string.

The bug is in 'isArraylike()':

return type === "array" || type !== "function" &&
		( length === 0 ||
		typeof length === "number" && length > 0 && ( length - 1 ) in obj );

It's the

(length - 1) in obj

that's the problem.

I'm not sure what the intention was with that check otherwise I'd submit a patch myself.

Attachments (0)
Change History (4)

Changed January 31, 2013 07:41PM UTC by gregoryb@ualberta.net comment:1

Oops, fogot jsFiddle link:

http://jsfiddle.net/HwxMX/

Changed January 31, 2013 07:55PM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed

Strings aren't one of the supported types. http://api.jquery.com/jQuery.each/

Changed February 18, 2013 05:16PM UTC by Alex comment:3

Shouldn't it report that then? Instead of this obscure error?

Cheers,

Alex

Changed February 18, 2013 05:23PM UTC by dmethvin comment:4

Sorry but we're not getting into the business of checking all incoming args to see if someone passed invalid data, and then giving long descriptive error messages. Read the API documentation.