I've been trying multiple codes but I cannot seem to crack it.
I have a base URL that directs to the "About" page in every BMC journal page https://biomedcentral.com/about
I want to target the "About" pages of ALL BMC journals in my list
example 1: BMC Primary Care = https://bmcprimcare.biomedcentral.com/about
example 2: BMC Neuroscience = https://bmcneurosci.biomedcentral.com/about
As you can see, each journal page differs in its initial code (above in bold).
I need a JavaScript code that will produce the same base URL multiple times, but each time with a different journal code. The goal is to target the "About" pages from ALL journals on my list.
I would so appreciate the help!!
You can achieve it by using Array.map() along with String.split() and Template literals (`)
const baseURL = 'https://biomedcentral.com/about';
const journalCodeArr = ['bmcprimcare', 'bmcneurosci'];
const result = journalCodeArr.map((journalCode) => {
const splitBaseURL = baseURL.split('//');
return `${splitBaseURL[0]}//${journalCode}.${splitBaseURL[1]}`
});
console.log(result);