“cara mengulang string di javascript” Kode Jawaban

cara mengulang string di javascript

let text = 'Hello world!';
let result = text.repeat(4);

console.log(result);
Mehedi Islam Ripon

Karakter Ulangi JavaScript

var a="a";
var aaa=a.repeat(3); // "aaa"
Grepper

String Ulangi JavaScript

// best implementation
repeatStr = (n, s) => s.repeat(n);
Fylls

Ulangi fungsi javascript

setInterval(function(){
  console.log("Hello");
  console.log("World");
}, 2000); //repeat every 2s
TalalDEV

Ulangi string ulangi string-javascript

function repeatStringNumTimes(str, num) {
  if (num < 1) {
    return "";
  } else {
    return str + repeatStringNumTimes(str, num - 1);
  }
}
Angry Alpaca

Fungsi Ulangi JavaScript

/* The string.repeat(n) method constructs and returns a new string
with "n" number of copies. */

const chorus = "Because I'm happy. ";
console.log(`Chorus lyrics: ${chorus.repeat(3)}`);
// → "Chorus lyrics: Because I'm happy. Because I'm happy. Because I'm happy. "

// Use within a function
greeting = (n, words) => words.repeat(n);
console.log(greeting(5, "howdy ")); 
// → "howdy howdy howdy howdy howdy "
Intra

Jawaban yang mirip dengan “cara mengulang string di javascript”

Pertanyaan yang mirip dengan “cara mengulang string di javascript”

Lebih banyak jawaban terkait untuk “cara mengulang string di javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya