JS: Add ellipsis if string length exceeded 50 characters

Is it possible to use ternary operator to add ‘…’ if string exceeds 50 characters?

I tried it like this but it doesn’t work.

{post.title.substring(0, 50) + post.title.length > 50
                    ? '...'
                    : ''}

Any suggestion?

22 thoughts on “JS: Add ellipsis if string length exceeded 50 characters”

Leave a Comment