📜  在 js 中用新行替换逗号 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:24.748000             🧑  作者: Mango

代码示例1
let availableData = "Hello, Hi, Wassup";
let desiredData = replaceCommaLine(availableData);
function replaceCommaLine(data) {
    //convert string to array and remove whitespace
    let dataToArray = data.split(',').map(item => item.trim());
    //convert array to string replacing comma with new line
    return dataToArray.join("\n");
}
console.log(desiredData);