Jak zrobić ciąg krótszy JavaScript
const string = "Name".slice(0, 250).concat('...');
const string2 = "Name".substring(0, 250).concat('...');
Wide-eyed Warbler
const string = "Name".slice(0, 250).concat('...');
const string2 = "Name".substring(0, 250).concat('...');
var string = "ABCDEFG";
var truncString = string.substring(0, 3); //Only keep the first 3 characters
console.log(truncString); //output: "ABC"
const truncate = (string) => {
const newText = string.substring(0, 5);
return newText;
};
console.log(truncate("abcdefgh"));
//abcde
/**
* Check if an element is truncated.
*/
function isTruncated(el) {
return el.scrollWidth > el.clientWidth
}