Word to Array

andaeiii

Ande Caleb

Posted on July 26, 2022

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

💖 💪 🙅 🚩
andaeiii
Ande Caleb

Posted on July 26, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related