“JavaScript string truncate” Kode Jawaban

Cara membuat string javascript yang lebih pendek

const string = "Name".slice(0, 250).concat('...');
const string2 = "Name".substring(0, 250).concat('...');
Wide-eyed Warbler

JavaScript string truncate

var string = "ABCDEFG";
var truncString = string.substring(0, 3); //Only keep the first 3 characters
console.log(truncString); //output: "ABC"
TC5550

Potong string-javascript

function truncateString(str, num) {
  return str.length > num ? str.slice(0, num) + "..." : str;
}
Angry Alpaca

JavaScript Truncate String Word Full

const truncate = (str, max, suffix) => str.length < max ? str : `${str.substr(0, str.substr(0, max - suffix.length).lastIndexOf(' '))}${suffix}`;

// Example
truncate('This is a long message', 20, '...'); 
Batman

cara memotong string di javascript

function truncateString(str, num) {
  if (str.length > num) {
    return str.slice(0, num) + "...";
  } else {
    return str;
  }
}
Important Impala

Substring

const str = 'Mozilla';

console.log(str.substring(1, 3));
// expected output: "oz"

console.log(str.substring(2));
// expected output: "zilla"
Prickly Pony

Jawaban yang mirip dengan “JavaScript string truncate”

Pertanyaan yang mirip dengan “JavaScript string truncate”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya