文字列を切り詰める
893 ワード
function truncateString(str, num) {
return str;
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
// slice() method should work for this as well; whats slice?
let name = "randy";
console.log(name.slice(0, 3)); // will display ran
function truncateString(str, num) {
if (str.length > num) {
return str.slice(0, num) + "...";
}
return str;
}
console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8)); // will display "A-tisket..."
// console.log("A-tisket a-tasket A green and yellow basket".length); will display 43
Reference
この問題について(文字列を切り詰める), 我々は、より多くの情報をここで見つけました https://dev.to/rthefounding/truncate-a-string-5ae1テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol