JavaScript not in list | Example code

  • by

Use the Array includes() function to check the item in this list (array) or not in JavaScript. Using not operator with if statement to you can make it a falsy statement.

['a', 'b', 'c'].includes('b')

JavaScript is not on the list

Simple exmaple code Determine if the string is in the list in JavaScript.

<!DOCTYPE html>
<html>
<body>

  <script>
   var res = !['a', 'b', 'c'].includes('b')
   console.log(res)

   if (!['a', 'b', 'c'].includes('b')){
    console.log("b is in list")
   } else{
    console.log("b is NOT in list")
   }

</script>

</body>
</html> 

Output:

JavaScript not in list

Simple code

var myList=["a", "b", "c"];
mylist.includes("d")//returns true or false

Do comment if you have any doubts or suggestions on this js list topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Tags:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.