JSFiddle - React, Tailwind, and code Playground

by LyndseyB

JavaScript

var text = ["Tom exhibited.","Amy Lawrence was proud and glad, and she tried to make Tom see it in her face - but he wouldn't look.","Tom was tugging at a button-hole and looking sheepish.","Two thousand verses is a great many - very, very great many.","Tom's mouth watered for the apple, but he stuck to his work."];

for(x in text) {
    var str = text[x];
    if(str.length<=55) {
       // console.log(str);
    } else if(str.length > 55) {
       var substr = str.trim().substring(0,40);
       console.log(substr);
    }
}