Reputation:
let name = "Stack Overflow"
I want to ignore space and create an array with each alphabet as an element.
Expected result: ["S", "t", "a", "c", "k", "O", "v", "e", "r", "f", "l", "o", "w"]
Upvotes: 3
Views: 142
Reputation: 4580
On javascript you're looking for spread (link to docs) operator associate with a filter method (link to docs):
The spread will create an array with all chars from your string, the filter will ignore all spaces for you:
let name = "Stack Overflow"
let myArray = [...name].filter(letter => letter !== ' ');
// myArray will be:
[
'S', 't', 'a', 'c',
'k', 'O', 'v', 'e',
'r', 'f', 'l', 'o',
'w'
]
This also right for es6 ! Cheer
Upvotes: 0