Reputation: 123
I must iterate in a string like this:
message: dob cat dog dog
cat cat
Like a multiple separate I need white space and newline (\n) so my function is:
message.split(' ,\n').forEach(function(x){
...});
But this is not work. Anyone can help me?
Upvotes: 0
Views: 61
Reputation: 1750
You can use this also.
message.split(/\s/)
Demo : Click here
Upvotes: 0
Reputation: 1041
I would rather use regex:
message.split(/[\ \n]/)
[] - matches one of characters in this group,
'\ ' - will match single space,
'\n' - will match new line
Upvotes: 2