DEV Community

Cover image for 4 Ways to Convert String to Character Array in JavaScript

4 Ways to Convert String to Character Array in JavaScript

Samantha Ming on March 18, 2020

Here are 4 ways to split a word into an array of characters. "Split" is the most common and more robust way. But with the addition of ES6, there ...
Collapse
 
karataev profile image
Eugene Karataev

Thanks for the post! I didn't know that split method and spread operator have different behavior.
I looked at grapheme clusters one step deeper and learned that even ... may give wrong results for complex emojis.

console.log([...'πŸ³οΈβ€πŸŒˆ'].length) // 6 πŸ€”

There is even grapheme splitter library to break strings in characters as expected.

Collapse
 
aralroca profile image
Aral Roca

I didn't know that .bold exist! Heh

Collapse
 
samanthaming profile image
Samantha Ming

Ya, it does! But don't use it lol because it's deprecated. I just wanted to find a method that was only part of String and not an Array and that's the one I found. Which made me realize these two objects have similar methods πŸ˜‚

Collapse
 
martinadamsdev profile image
Martin Adams

Intersting and inspiring article!

Can I translate it into Chinese to help more developers?

I will give credit at the top of the article.

Collapse
 
samanthaming profile image
Samantha Ming

You bet Jack! My code notes aren't mean to be shared! Thank you so much for wanting to translate it πŸ‘

You can find the markdown and original image in my repo:
github.com/samanthaming/samanthami...

(I'd recommend checking the markdown in my repo because I keep that up to date, and sometimes I might forget to edit the article on dev πŸ˜…)

Let me know if you need anything that can help with your translation 😊

Collapse
 
martinadamsdev profile image
Martin Adams

ok. star and watch.

Collapse
 
thehanna profile image
Brian Hanna

This is so incredibly in depth! I always learn something new from your posts, and I've been using JS for more than 20 years! Thank you!

Collapse
 
samanthaming profile image
Samantha Ming

Thanks Brian! That makes me so happy to hear that you still learned something even with your extensive background. I want to follow your attitude, have that StudentMindset even after 20 years. I think it’s one of the thing I love about tech, it’s always evolving, so you never stop learning πŸ˜„πŸ‘

Collapse
 
raquelsartwork profile image
Raquel Santos | RS-coding

Thank you so much for your posts. really easy to understand . I am more visual person and your posts are amazing throw that. thank you !

Collapse
 
samanthaming profile image
Samantha Ming

Same! I just need to learn video editing and hopefully one day I can make video tutorials of these πŸ˜†

Thank you for your kind words, so glad you found my code notes helpful 😊 Btw, I also have a series where I try to explain common code interview questions using pictures that you might also like πŸ‘‰ samanthaming.com/pictorials/

Collapse
 
isajal07 profile image
Sajal Shrestha

I always loved your blogs. Keep it coming, Samantha. πŸ˜„

Collapse
 
samanthaming profile image
Samantha Ming

You bet! Thanks for the encouragement! So happy you found them helpful πŸ˜ŠπŸ‘