I have to get a URL using javascript that contains the following string is like
karachi-hotels
abu-dubai-hotels
phi-phi-island-hotels
phi-phi-hotels
kaula-lampur-hotels
using javascript I want to get the city name like
karachi
abu-dubai
phi-phi-island
and etc
To remove "-hotels", you can use native replaceAll() and split() methods.
var hotels = "karachi-hotels abu-dubai-hotels phi-phi-island-hotels phi-phi-hotels kaula-lampur-hotels";
var cities = hotels
.replaceAll("-hotels", "") // It removes all "-hotels"
.split(" "); // It returns an array of all locations.
console.log(cities) // [ 'karachi', 'abu-dubai', 'phi-phi-island', 'phi-phi', 'kaula-lampur' ]