Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@martingaido
Created August 1, 2020 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martingaido/48e546ea7dd22c1e4e02f8215e682465 to your computer and use it in GitHub Desktop.
Save martingaido/48e546ea7dd22c1e4e02f8215e682465 to your computer and use it in GitHub Desktop.
Checking if String contains Substring
/* 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