Let me share with you this scenario:
var eventTypes = ['#course', '#bundle'];
var customEvent = ['#coursebar']
I am looking to determine if any of the strings in customEvent
is a superstring (starts with) any value from the strings in eventTypes
. If so, I want to return the first matching value.
I've experimented with using find
and includes
, but haven't been able to achieve the desired outcome. Most examples I came across dealt with comparing just one string against an array.
To make things clearer, here are some expected results:
var eventTypes = ['#course', '#bundle'];
// SCENARIO 1
var customEvent = ['#coursebar'] // should return '#coursebar'
// SCENARIO 2
var customEvent = ['#foo'] // should return undefined
// SCENARIO 3
var customEvent = ['#coursebar, #coursebaz'] // should return either '#coursebar' OR '#coursebaz'
I'm aware that accomplishing this using for loops is possible, but I'm curious if there's a more concise and modern approach available.