Skip to main content

doesStringContainAny

doesStringContainAny checks whether a string contains any of the items in a given array. It returns true as soon as one of the items is found within the string, otherwise it returns false.

It's a handy shortcut when you'd otherwise write several str.includes(...) checks chained together with ||.

Usage examples

Basic

// true — the string contains 'world'
window.BAO.utils.doesStringContainAny('hello world', ['world', 'foo'])

// false — none of the items are present
window.BAO.utils.doesStringContainAny('hello world', ['foo', 'bar'])

Checking a URL for query params

const url = window.location.href

if (window.BAO.utils.doesStringContainAny(url, ['?variant=', '&variant='])) {
// The URL references a specific variant
}