Table of Contents
- Understanding the
- A Real Example
- What about Starting Midway?
- Case Sensitivity and Type Checking
- Browser Compatibility
includes() method. Let's dive into how this works!
includes() method is like asking the fruit vendor, "Do you have any apples in this basket?" If the answer is yes, the method returns
true; if not, it returns
Here's the basic syntax:
valueToFind: This is the apple you're looking for, or in technical terms, the value you want to check for in the array.
fromIndex(optional): This is where you start looking in your basket. If you don't specify this, it starts from the beginning.
A Real Example
What about Starting Midway?
You might want to start checking from a specific point in the array, not always from the beginning. This is where
fromIndex comes in handy. Consider you're only interested in the latter half of your language list:
Case Sensitivity and Type Checking
includes() method is widely supported in modern browsers. However, if you're writing code for an environment that doesn't support ES6 (where
includes() was introduced), you might need to use alternatives like