One option is to use a regular expression, for example:
str = "how are you? hope you are doing good"; var tokens = str.split(/(\?)/)
but this will lead to question marks in their own token: how are you,?, hope you are,?, doing good
The best way:
var tokens = str.match(/[^?]+\?*/g)
It will also contain a few question marks: "hello??? how are you?"
source share