javascript - Replace a string word with empty space with js -


i have following string:

var string = "deluxe 3 bed  private" 

and following code replace "private" word empty space:

var rooms = ["basic", "standard", "superior", "deluxe", "private"]; //var room = "room"; vwo_$(document).ready(function(){    wri.eventbus.on('ui:microsite:availabilitystore:refresh', function(){     var roomname = $(".roomnamelink");     roomname.each(function(){       (var = 0; < rooms.length; i++) {         var pattern = "[^\s]" + rooms[i];         var regex = new regexp(pattern);         string = string .replace(regex, " ");       }     });   }) 

but regex wrong.

if word "private" found in string want replaced empty space.

var string = "deluxe 3 bed" 

i want replace of words found in rooms array empty space can use 1 regex possible words

var regex = /\b(basic|standard|superior|deluxe|private)\b/gi 

and use string#replace method

var string = "deluxe 3 bed  private" string.replace(regex, '') 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -