Avatar ·

How to check if a string contains a substring in JavaScript?

Hello everyone! I just started learning JavaScript and encountered a task: I need to check if a string contains a specific word or set of characters. For example, I have a variable with a user's email:\n\n```javascript\nlet email = "ivan.petrov@gmail.com";\n```\n\nAnd I need to determine if this email contains the "@" character. I tried using the `==` and `===` operators, but they compare entire strings, not check for inclusion. I also heard about the `indexOf` method, but I didn't fully understand how to use it correctly.\n\nPlease tell me, what are the ways in JavaScript to check for the presence of a substring in a string? Preferably with code examples and an explanation of which method is best to use in modern projects. Thanks in advance!\n<<>>\n

The most modern way: the includes() method