javascript / beginner
Snippet
Checking for Elements with Array.includes()
The .includes() method is a simple way to check if an array contains a specific value. It returns a boolean (true or false).
snippet.js
1
2
3
4
const fruits = ['apple', 'banana', 'orange'];const hasMango = fruits.includes('mango');console.log('Contains mango:', hasMango);
nodejs
Breakdown
1
fruits.includes('mango')
Checks the array for the string 'mango'.
2
const hasMango = ...
Stores the boolean result (false in this case).