Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to check if a string contains a certain letter in js

// use the variable.includes() 
const myString = "hello world!"
if(myString.includes("hello")){
  // do something 
}else{
  //also do something
}
Comment

js check if string contains character

"FooBar".includes("oo"); // true

"FooBar".includes("foo"); // false

"FooBar".includes("oo", 2); // false
Comment

js check if string contains character

if (your_string.indexOf('hello') > -1)
{
  alert("hello found inside your_string");
}
Comment

check if specific letter exist in string javascript

// With ES6 MDN docs .includes()
"FooBar".includes("oo"); // true
"FooBar".includes("foo"); // false
"FooBar".includes("oo", 2); // false (2 is the start position for the search)

// E: Not suported by IE - instead you can use the Tilde opperator ~ (Bitwise NOT) with .indexOf()
~"FooBar".indexOf("oo"); // -2
~"FooBar".indexOf("foo"); // 0
~"FooBar".indexOf("oo", 2); // 0 (parameter 2 is the start position for the search)
Comment

PREVIOUS NEXT
Code Example
Javascript :: append element in a div as first child 
Javascript :: node js starting template 
Javascript :: last element in array 
Javascript :: string to jsonobject gson 
Javascript :: cannot find module @babel/compat-data/data/corejs3-shipped-proposals 
Javascript :: addEventListener call only once 
Javascript :: html parser javascript 
Javascript :: outer width jquery 
Javascript :: package json scripts multiple commands 
Javascript :: tsconfig.json not generated 
Javascript :: trigger play video jquery 
Javascript :: javascript add class to element 
Javascript :: javascript cookies store object 
Javascript :: javascript element in array 
Javascript :: js test undefined 
Javascript :: react js nesting 
Javascript :: set header as json in laravel 
Javascript :: iframe reload parent page 
Javascript :: how to add toaster in angular 9 
Javascript :: split url javascript 
Javascript :: nextjs check production or development environment 
Javascript :: export apk react native 
Javascript :: access session data from ejs view 
Javascript :: regexp object javascript 
Javascript :: miles to metres js 
Javascript :: javascript string interpolation 
Javascript :: javascript create array of objects from multiple arrays 
Javascript :: Change the HTML of an element 
Javascript :: remove duplicates objects from array javascript 
Javascript :: comprobar si un objeto esta vacio javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =