DEV Community

Cover image for Word to Array
Ande Caleb
Ande Caleb

Posted on

1 1

Word to Array

a simple way to convert a String to an Array is by Spreading it... within the array brackets [ ... ] symbols, which is easier than using the String.prototype.split()

let str = 'Aminu Kano';

array = [ ...str ]; //break the array into letters. 



Enter fullscreen mode Exit fullscreen mode

This outputs an array of 10 elements. which becomes

[ "A", "m", "i", "n", "u", " ", "K", "a", "n", "o" ];

//same result can be achieved using the code below. 

str.split("");

Enter fullscreen mode Exit fullscreen mode

but the latter seems much easier and cleaner

hope this helps..

Top comments (2)

Collapse
 
link2twenty profile image
Andrew Bone
Comment hidden by post author
Collapse
 
andaeiii profile image
Ande Caleb • Edited

Thanks, really appreciate

Some comments have been hidden by the post's author - find out more

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay