I have an array of urls like this:
[
'https://subdomain1.example.com/foo-bar/',
'https://subdomain2.example.com/foo-bar',
'https://subdomain2.example.com/foo-bar',
'https://subdomain2.example.com/foo-bar',
'https://subdomain2.example.com/foo-bar'
]
I need to search inside it to match the user input with the subdomain part of the url, I'm trying with thism line of code to achive it:
const searched = urlList.find( el => el.includes( match[1].toLocaleLowerCase() ) )
console.log(searched.length)
If the input is find, I need to replace the second part of the url, in my case /foo-bar with /foo-baz or /foo-baz-bar to obtain a response for the user that is something like https://subdomain2.example.com/foo-bar-baz/.
At the moment I'm not sure how to proceed, is there any function in JS that can help me?
URLconstructor: developer.mozilla.org/en-US/docs/Web/API/URL/URLsubdomain1and then you want to findsubdomain1.example.com/...? Also, what do you mean when you say you need to "obtain [...] something like"? Because questions should leave things up to guesses: what do you need, exactly rather than approximately?