How can I split this array with commas?
I have multiple arrays
[ "LeadershipPress" ]
[ "BusinessLeaderLeadershipPress" ]
[ "LeaderLeadershipPoliticsPress" ]
etc.
scraper.scrapeListingPages('article.article', (item) => {
var categories = $(item).find('a[rel = "category tag"]').text().split();
console.log(categories);
categories.forEach(function(i){
$(i).find('a[rel = "category tag"]')
console.log(i);
})
});
Right now my output in the console is
Array [ "BusinessLeaderLeadershipPress" ]
BusinessLeaderLeadershipPress
I want to split the categories into an array with commas without having to use separator, limits or regex because I have multiple random arrays.
Is there a way I can use a forEach or for loop to accomplish this?
The result I want is [ "Business, Leader, Leadership, Press" ]
Thanks
split(). Otherwise it makes an array of single characters.Array.prototype.flat()to thecategoriesarray. Also seeString.prototype.split()for more information on proper splitting.