You need some sort of text mining library to do this and more specifically what you want to do it’s called tokenization:
Each word in a string is categorized as a lexical token with a syntactical role e.g verb, pronoun etc.
See tokenization and text mining for more info.
There is a Javascript library called RiTaJS which gives you the ability to tokenize a string into parts of speech.
From the site
You can use
RiTa.getPosTags
to analyze the part-of-speech (or POS) for you.
RiTa.getPosTags("I am hungry");
The outcome would be:
["prp", "vbp", "jj"]
To see what these tokens mean, check the reference
4
solved Array to sort worlds by word class in a text [closed]