I am using .map function to display a description. I would like to show only 35 characters followed by … only if it exceeds 35 chars
e.g. This is description of thirty five …
I am trying to show as below
<div className='desc'>{student.description.substring(0,35)+"..." } </div>
How to add logic for "…" so that it only shows when student.descripton.length() > 35 ?
2
Answers
Do a ternary, checking the length.
Create a function that determines the length of the string and returns the appropriate text based on that length, and then call it from the JSX.