var convertToArray = (txt) => {
let arr = txt.split(" ");
console.log(arr);
};
convertToArray("Hello World ");
At the end of Hello World
I have 4 spaces and now I need to take that whitespace as element of an array.
E.g.: ["Hello", "World", " "]
2
Answers
You should use this code:
Use
match
instead ofsplit
and filter out the single spaces. Something like: