“Ganti JS” Kode Jawaban

Mengganti karakter dalam string javascript

var myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');

console.log( newStr );  // "this-is-a-test"
Exuberant Emu

JavaScript mengganti string

var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method success
Batman

JS menggantikan karakter dalam string

var str = "Original string!";
var str = str.replace("Original", "New");
Poised Penguin

JavaScript Ganti semua kemunculan string

function replaceAll(str, find, replace) {
    var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    return str.replace(new RegExp(escapedFind, 'g'), replace);
}
//usage example
var sentence="How many shots did Bill take last night? That Bill is so crazy!";
var blameSusan=replaceAll(sentence,"Bill","Susan"); 
Grepper

Ganti JS

// Replace All
str = str.replace(/_/g, ' ');
Lucas Juan

Ganti JS

function spinWords(pw){
	let a = ''
    if(pw.length <= 5){
      a +=pw.split("").reverse()
      console.log(a.replaceAll(',' , ''))
    }else {
      console.log("olá")
    }
}

let hey = "hello";
spinWords(hey) // olleh
Wide-eyed Wolf

Jawaban yang mirip dengan “Ganti JS”

Pertanyaan yang mirip dengan “Ganti JS”

Lebih banyak jawaban terkait untuk “Ganti JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya