请麻烦我怎么做
这是我的功能
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));之类的字符串上执行我的函数。
任何人都可以帮助我,谢谢