如何從 JavaScript 中的字串中刪除“,”
我們得到了一個主字串和一個子字串,我們的任務是建立一個函式 shedString(),它接受這兩個引數並返回一個沒有子字串的主字串版本。
例如 −
shedString('12/23/2020', '/');應該返回一個字串 −
'12232020'
現在讓我們為該函式編寫程式碼 −
範例
const shedString = (string, separator) => {
//we split the string and make it free of separator
const separatedArray = string.split(separator);
//we join the separatedArray with empty string
const separatedString = separatedArray.join("");
return separatedString;
}
const str = shedString('12/23/2020', '/');
console.log(str);輸出
此程式碼在控制檯中的輸出為 −
12232020
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP