JSFiddle - React, Tailwind, and code Playground
JavaScript
/**
* Extend the Array object
* @param candid The string to search for
* @returns Returns the index of the first match or -1 if not found
*/
Array.prototype.searchFor = function(needle) {
for (var i=0; i<this.length; i++)
if (this[i].indexOf(needle) == 0)
return i;
return -1;
};
someWebsites = ['somesite.com/subdir','someotherwebsite.com']
function checkTabURL(url) {
switch (someWebsites.searchFor(url)) {
case 0:
console.log('case 0');
break;
case 1:
console.log('case 1');
break;
default:
console.log('default');
break;
}
}
checkTabURL('somesite.com');