Cómo hacer una cadena más corta 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"
function truncateString(str, num) {
return str.length > num ? str.slice(0, num) + "..." : str;
}
function truncateString(str, num) {
if (str.length > num) {
return str.slice(0, num) + "...";
} else {
return str;
}
}
_.truncate('hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there, neighbo...'
_.truncate('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' '});
// => 'hi-diddly-ho there,...'
_.truncate('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/});
// => 'hi-diddly-ho there...'
_.truncate('hi-diddly-ho there, neighborino', { 'omission': ' [...]'});
// => 'hi-diddly-ho there, neig [...]'
var length = 3;
var myString = "ABCDEFG";
var myTruncatedString = myString.substring(0,length);
// The value of myTruncatedString is "ABC"