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.
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("");
but the latter seems much easier and cleaner
hope this helps..
Top comments (2)
Hello!
If you'd like, you can add syntax highlighting (colors that make code easier to read) to your code block like the following example.
This should make it a bit easier to understand your code. 😎
In order to use this in your code blocks, you must designate the coding language you are using directly after the first three back-ticks. So in the example above, you'd write three back-ticks js (no space between the two), put the code beneath (e.g.
console.log('Hello world!');
), then three back-ticks beneath that to close the code.Here's an image that shows how it's written!
Thanks, really appreciate
Some comments have been hidden by the post's author - find out more