Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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