Skip to content

Instantly share code, notes, and snippets.

@dhbalaji
Created April 16, 2020 17:29
Show Gist options
  • Save dhbalaji/31c0c9af15bc4433039a860cdfff5159 to your computer and use it in GitHub Desktop.
Save dhbalaji/31c0c9af15bc4433039a860cdfff5159 to your computer and use it in GitHub Desktop.
Check if string contains substring, array has an item

includes in ES6 to search for string, item in array

TLDR: Of course from different prototypes.

   const str = 'We are Indians';
   const subStr = 'India'
   const hasSubStr = str.includes('India');
   
   
   const countries = ['India', 'USA', 'UK'];
   const hasItem = countries.includes(subStr);
   
   console.log(hasSubStr, hasItem); // true, true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment