input = "Hello my name is Luke" inputWithoutSpaces = input.replace(/s/g, "_"); // s == space console.log(inputWithoutSpaces); //Output: "Hello_my_name_is_Luke"