How to Check if String Contains Array of Substrings in Javascript

 

This is very basic tutorial of javascript where you will learn how to check if string contains array of substrings.

const validDomains = ['gmail.com', 'hotmail.com', 'yahoo.com'];

const email = 'I have accounts at gmail.com and yahoo.com';

const result = validDomains.every(domain => email.includes(domain));

console.log(result);
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
    <script src="script.js"></script>
</body>
</html>