replace with comma in javascript code example

Example 1: replace comma by new line in js

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);

Example 2: how to replace commas with nothing in javascript

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

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