Skip to content
This repository

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

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

3 participants

Patrick Corcoran Jeremy Ashkenas Paul Harper
Patrick Corcoran

_.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!

Jeremy Ashkenas
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.

Jeremy Ashkenas jashkenas closed this August 16, 2011
Paul Harper

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

Jeremy Ashkenas
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
Something went wrong with that request. Please try again.