Allow string-to-array conversion in _.toArray() #276

Closed
pcorcoran opened this Issue Aug 15, 2011 · 3 comments

Projects

None yet

3 participants

@pcorcoran

_.toArray('abc') today throws a TypeError. It would great if it instead returned ['a','b','c']. A simple str.split('') would do.

(I understand the line in the sand regarding string functions. But treating strings as collections is a nice-n-functional thing to allow.)

Thanks!

@jashkenas
Owner

Nope, sorry. It sounds like you've already read all the tickets discussing supporting strings as arrays of characters, so no need to rehash here.

TypeError is definitely what you want in this case.

@jashkenas jashkenas closed this Aug 16, 2011
@benekastah

@jashkenas Could you please link to any issues that cover why underscore doesn't support strings as arrays of characters? Thanks.

@jashkenas
Owner

I don't know them off the top of my head, but Github Issues search should be able to help you.

Underscore doesn't support strings as arrays of characters because strings aren't arrays of characters in JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment