Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
JavaScript. How to check if a random URL contain values of an array
const location = ['Bradenton', 'Broward', 'Miami', 'Orlando', 'Palm Beach'];
var url = '?_dFR[location_page][0]=Miami&_dFR[location_page][1]=Orlando&_dFR[make][0]=Acura&_dFR[make][1]=Audi&_dFR[make][2]=BMW&_dFR';

As you see url have Miami and Orlando that have in location.

The result should be: ['Miami', 'Orlando']. I tried to use regex but it is too complex. Is there an easier way?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you're looking for filter

const locationList = ['Bradenton', 'Broward', 'Miami', 'Orlando', 'Palm Beach'];
const url = '?_dFR[location_page][0]=Miami&_dFR[location_page][1]=Orlando&_dFR[make][0]=Acura&_dFR[make][1]=Audi&_dFR[make][2]=BMW&_dFR';

const results = locationList.filter(currentLocation => url.includes(currentLocation));

console.log(results);

You also can use toLowerCase() and toUpperCase() to ignore case sensitive for your matches

const locationList = ['Bradenton', 'Broward', 'Miami', 'Orlando', 'Palm Beach'];
//lowercase for `orlando` and uppercase for `MIAMI`
const url = '?_dFR[location_page][0]=MIAMI&_dFR[location_page][1]=orlando&_dFR[make][0]=Acura&_dFR[make][1]=Audi&_dFR[make][2]=BMW&_dFR';

const results = locationList.filter(currentLocation => (url.includes(currentLocation.toLowerCase()) || url.includes(currentLocation) ||  url.includes(currentLocation.toUpperCase())));

console.log(results);

Regex version

const locationList = ['Bradenton', 'Broward', 'Miami', 'Orlando', 'Palm Beach'];
//lowercase for `orlando` and uppercase for `MIAMI`
const url = '?_dFR[location_page][0]=MIAMI&_dFR[location_page][1]=orlando&_dFR[make][0]=Acura&_dFR[make][1]=Audi&_dFR[make][2]=BMW&_dFR';

const results = locationList.filter(currentLocation => new RegExp(currentLocation, 'i').exec(url));

console.log(results);

about 4 years ago · Juan Pablo Isaza Report

0

const locations = ['Bradenton', 'Broward', 'Miami', 'Orlando', 'Palm Beach'];
var url = '?_dFR[location_page][0]=Miami&_dFR[location_page][1]=Orlando&_dFR[make][0]=Acura&_dFR[make][1]=Audi&_dFR[make][2]=BMW&_dFR';

const foundLocs=locations.filter(l=>url.includes(l))

console.log(foundLocs);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!