Treating strings as an array of chars, maybe a new Char type?

String's are sort of a collection of Char's, but immutable. So, why not make it more functional and iterative?

Right now, to treat string as an array we have to .split('') and then .join('') back, but what if this would happen more seamlessly?

You can sort of achieve it with this hacky hack: =

And then if you call

"hello".map((e,i,self) => self[self.length-1-i])

Which will return ['o', 'l', 'l', 'e', 'h'].

This kinda works with methods that don't mutate the string (previously array). But still yeilds some weird behavior.

for(a in str){ console.log(a) } // 0, 1, 2, 3, 4, 5, map, filter

And will not with things that do

String.prototype.reverse = Array.prototype.reverse

Will yield and error saying that "we can assign value to readonly property".

Just imagine how amazing, clean and simple would JS be. Heck, we are going functional way, which is great, why not go all the way.


will become




will become


Is this even necessary? Are there any better ideas how to go about this?

You don't have to do the horrifically bad practice of mutating objects you don't own to do that; you can, mapper).join('').

What would be the benefit of a Char type of length 1, especially considering that :poop: has a length of 2, and :rainbow_flag: has a length of 6?

If you're talking about cases where you want to map one string to another one character at a time (but not one code point, or one grapheme cluster at a time); or use cases where you want to reverse a string by character (but not by code point, or by grapheme cluster, or if the text is RTL), then that would be interesting to hear more about.