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
- 2.0 Build
- 1.0 Build
// 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'])
// true — the string contains 'world'
doesStringContainAny('hello world', ['world', 'foo'])
// false — none of the items are present
doesStringContainAny('hello world', ['foo', 'bar'])
Checking a URL for query params
- 2.0 Build
- 1.0 Build
const url = window.location.href
if (window.BAO.utils.doesStringContainAny(url, ['?variant=', '&variant='])) {
// The URL references a specific variant
}
const url = window.location.href
if (doesStringContainAny(url, ['?variant=', '&variant='])) {
// The URL references a specific variant
}