“Potong string di JavaScript” 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

cara memotong string di javascript

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

Potong string di JavaScript

_.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 [...]'
Light Ladybird

Memotong string menggunakan javascript

var length = 3;
var myString = "ABCDEFG";
var myTruncatedString = myString.substring(0,length);
// The value of myTruncatedString is "ABC"
Light Ladybird

Jawaban yang mirip dengan “Potong string di JavaScript”

Pertanyaan yang mirip dengan “Potong string di JavaScript”

Lebih banyak jawaban terkait untuk “Potong string di JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya