JSFiddle - React, Tailwind, and code Playground

by PenguinOfWar

JavaScript

$(document).ready(function() {

    var str = "第 四 届索尼 杯 婚 庆 视频大赛";
    //check if string length is over threshold
    if (str.length >= 10) {
        var str = str.substring(0, 10);
        var arr = str.split(" ");
        if (arr.length >= 5) {
            //remove last word after truncation
            arr.pop();
            console.log(arr);
            var str = arr.join(" ");
            console.log(str);
        } else {
            //return only truncated
            console.log("Only truncated");
            console.log(str);
        }
    } else {
         console.log("Not truncated");
         console.log(str);   
    }
});