Reputation: 149
I am trying to split string including string but space are also spitted.
my code:-
var a =' that i love
game1 ';
console.log(a.split(' '))
my current output is like:-
(57) ["↵", "", "", "", "", "", "", "", "", "that", "i", "love↵", "", "", "", "", "", "", "", "", "game1↵↵↵", "", "", "", ""]
Output that I am trying to get somthing like this:-
(4)[" that",'i',' love',' ↵game'];
How can I split string in such a way including space and line break??
Upvotes: 0
Views: 68
Reputation: 1330
You can use regex in split
.
var a =` that i love
game1 `;
console.log(a.split(/(\s+\S+\s+)/));
Upvotes: 1