Some & Every

The some() and every() methods operate on arrays (including arrays of objects).

some()

The some() method will return true if at least one item in the array matches a given condition.

some() applied to an array (Run Example)

<!DOCTYPE html>
<html>
    <head>
        <title>Example using some() method</title>
        <meta http-equiv="Content-Type" content="text/htmlcharset=utf-8">
        <meta http-equiv="Content-Language" content="en" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
        <script>
           let numbers = [1, 3, 6, 8, 11]
           let arrayContainsNumber = numbers.some(number => number === 6)

           console.log(`arrayContainsNumber is ${arrayContainsNumber}`)  // will display true, as the number 6 occurs at least once in the array
        </script>
    </head>
    
    <body>         
         <div>View the console output in browser's Web DevTools (F12)</div>
    </body>
</html>

every()

The every() method will return true if all of the items in the array matches a given condition.

every() applied to an array (Run Example)

<!DOCTYPE html>
<html>
    <head>
        <title>Example using every() method</title>
        <meta http-equiv="Content-Type" content="text/htmlcharset=utf-8">
        <meta http-equiv="Content-Language" content="en" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
        <script>
            let numbers = [1, 3, 6, 8, 11]
            let arrayContainsNumber = numbers.every(number => number === 6)

            console.log(`arrayContainsNumber is ${arrayContainsNumber}`)  // will display false, as the number 6 occurs only least once in the array
        </script>
    </head>
    
    <body>         
         <div>View the console output in browser's Web DevTools (F12)</div>
    </body>
</html>
 
<div align="center"><a href="file:///C|/Users/Derek/Documents/Notes/versionC/index.html" title="DKIT Lecture notes homepage for Derek O&#39 Reilly, Dundalk Institute of Technology (DKIT), Dundalk, County Louth, Ireland. Copyright Derek O&#39 Reilly, DKIT." target="_parent" style='font-size:0color:whitebackground-color:white'>&nbsp;</a></div>