Skip to content

How to Turn a String into an Array of Characters: 3 Ways to do so.

twitter logo github logo ・1 min read  

Here are 3 different ways to convert a string into an array of its characters in javascript.

const str = 'Hello';

//1. Using split() method
const arr1 = str.split('');

//2. Using spread operator
const arr2 = [...str];

//3. Using Array.from() method
const arr3 = Array.from(str);

Follow me on:
👉Facebook page:

twitter logo DISCUSS (3)
markdown guide

Why make it that easy when we can make it much more complicated?

const str = 'Hello';

// 4. Using destructering assignement, Array.from and its map function
const { length } = str;
const arr4 = Array.from({ length }, (...[,i]) => str[i])

// 5. Using Object.values and destructering the string
const arr5 = Object.values({ ...str });

Classic DEV Post from Mar 22

🦠🚪 Show your COVID19 work from home desk? 👩🏻‍💻🪑

What's your COVID19 work from home desk ?

Islam Sayed profile image
A Freelance Front-End Web Developer, tech writer, and mentor at Udacity.