I have a JSON object in WordPress that contains a list of URLs. I would like to determine the frequency of occurrence of the second part of each URL.
Currently, the code snippet below is able to extract the remaining part of the URL after the prefix https://www.example.co
. My next objective is to calculate the occurrence of the second part of the URL, which includes cat1, cat3, cat2, xmlrpc.php
.
var urlList = [
{
"URL": "https://www.example.co/cat1/aa/bb/cc",
"Last crawled": "Jun 23, 2019"
},
{
"URL": "https://www.example.co/cat2/aa",
"Last crawled": "Jun 23, 2019"
},
// ...Additional URL objects
{
"URL": "https://www.example.co/xmlrpc.php",
"Last crawled": "Jun 19, 2019"
}
]
const paths = urlList.map(value => value.URL.replace('https://www.example.co', ''));
//console.log(paths);
paths.forEach(function(item) {
var urlSecondPart = item.split("/")[1];
console.log(urlSecondPart);
});
Is there a way to achieve this calculation within my current forEach
loop?
Any assistance on this matter would be highly appreciated. Thank you.