JaSon JaSon - 1 year ago 74
jQuery Question

Check all matches with combined string + array

I'm trying to hide some unique links from a site's product listing page.
Those links' href attributes endings are set in my "hrefs" array.
I'd like to include only the endings (instead of the whole url-s), since the part before them are always the same.

The links which I want to hide from the site (in this case) are:


My script is the next, the problem is it is only hiding the first match ( https://www.example.com/products/details/4123 ).

var hrefs = [ "4123", "4124", "4130", ];
var fullhref = ("https://www.example.com/products/details/") + (hrefs);
return fullhref.indexOf(this.href) >-1;

So it can combine the first part of the url and the last part from the array and remove that link, but only the first one.
I need some help how could the code check all of the given url endings (and hide all)?

Answer Source

you can modify the array with a loop then use it to filter the selection.

var hrefs = [ "4123", "4124", "4130", ];

for(var i = 0; i< hrefs.length; i++){
hrefs[i] = "https://www.example.com/products/details/" + hrefs[i];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download