@JaySODec 05.2022 — #You can use the includes() method. This method returns a boolean value indicating whether the string contains the substring. Here's an example:
const str = 'The quick brown fox jumps over the lazy dog';
if (str.includes('fox')) { console.log('The string contains the substring "fox"'); }
Alternatively, you can use the indexOf() method to check for the presence of a substring in a string. This method returns the index at which the substring is found, or -1 if the substring is not found. Here's an example:
const str = 'The quick brown fox jumps over the lazy dog';
if (str.indexOf('fox') !== -1) { console.log('The string contains the substring "fox"'); }
Both methods work similarly, but includes() is easier to read and more concise. It's a newer method, so it might not be supported in older browsers. If you need to support older browsers, you can use indexOf() instead.