从类似于“ mystring”的字符串执行函数。truncate(5)

时间:2019-03-03 19:14:30

标签: javascript

请麻烦我怎么做

这是我的功能

function truncate(num) {
    var str;
    if (str.length > num && num > 3) { 
        console.log(str.length);
        return str.slice(0, num) + "..."; 

    } else if (str.length > num && num <= 3) {
        console.log('ok');
        return str.slice(0, num) + "..."

    } else {
        console.log(str.length);
        return str;
    }

}

我想在类似console.log('hello world!'。truncate(2));之类的字符串上执行我的函数。

任何人都可以帮助我,谢谢

0 个答案:

没有答案