Let's assume that you want to check if a string starts with multiple other strings.
For example, let's consider the following string:
javascriptlet string = 'Hello, my name is Elon';
Let's assume that you want to check if the string starts with 'lo' or 'He'.
You can do it using a conditional:
javascriptlet res = string.startsWith('lo') || string.startsWith('He'); console.log(res); // true
You can do it using an array:
javascriptlet res = ['lo', 'He'].some(word => string.startsWith(word)); console.log(res); // true
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.