Created
August 1, 2020 19:04
-
-
Save martingaido/48e546ea7dd22c1e4e02f8215e682465 to your computer and use it in GitHub Desktop.
Checking if String contains Substring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Checking if String contains Substring */ | |
const word = 'sunny day in manhattan'; | |
/* Old Way */ | |
word.indexOf('sun') !== -1; // true | |
/* 🚀 ES6 Way */ | |
word.includes('sun'); // true | |
/* Array */ | |
const weather = ['sunny', 'rainy', 'cloudy']; | |
weather.includes('sun'); // true | |
weather.includes('Sun'); // false - case sensitive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment