Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#13362 closed bug (notabug)

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

Reported by: gregoryb@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:


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.

Change History (4)

comment:1 Changed 6 years ago by gregoryb@…

Oops, fogot jsFiddle link:


comment:2 Changed 6 years ago by dmethvin

Resolution: notabug
Status: newclosed

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

comment:3 Changed 6 years ago by Alex

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

comment:4 Changed 6 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.