0

I am trying to see if a string contains keywords to determine if it is a town or road. Because of the number of different values, rather than writing:

(Road.search("Way") != -1) || (Road.search("Road") != -1) || (Road.search("Ave") != -1)

for each value, I wonder if there is an easier way?

Values are

Cl, Close, Rd, Road, Dr, Drive, Sq, Square, Way, Ave, Avenue, Gardens, Loke, Ct, Court, Terrace

0

1 Answer 1

5

Quick and easy with some regex:

if (/\b(road|rd|ave|avenue|cl|close)\b/i.test(string)) {
    // It's a road
}
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a limit to how may ors that you have?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.