Advertisement
xerocool-101

006 includes method

Apr 20th, 2025 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.47 KB | Software | 0 0
  1. // Real Use Case Example
  2. const blockedUsers = ["user1", "user2"];
  3.  
  4. if (blockedUsers.includes(currentUser)) {
  5.   console.log("Access denied");
  6. }
  7.  
  8. // String
  9. "Hello".includes("hello"); // false ❗️
  10. "Hello".toLowerCase().includes("hello"); // true
  11.  
  12. // Array
  13. const fruits = ["apple", "banana", "orange"];
  14.  
  15. console.log(fruits.includes("banana")); // true
  16. console.log(fruits.includes("grape"));  // false
  17. console.log(fruits.includes("apple", 1)); // false (starts at index 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement