I need to shorten text after 50 characters but if the 50th char is at the middle of a word - cut only after the word and not before.
example text: Contrary to popular belief, Lorem Ipsum is not simply text (59 chars)
expected output: Contrary to popular belief, Lorem Ipsum is not simply (54 chars)
I was trying this: text.substr(0,50).lastIndexOf(' ')); - not good for me cause it cuts of the "simply" and I want the simply to be at the shorten text. Thanks for the help!