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

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 :: export socket io connection in react 
Javascript :: mern heroku Error: ENOENT: no such file or directory 
Javascript :: form data to json 
Javascript :: set cookie in javascript 
Javascript :: install video-react 
Javascript :: how to disable eval in javascript 
Javascript :: creat and move square using js 
Javascript :: Getting Search Parameters From A URL As An Array 
Javascript :: json returning object object 
Javascript :: kendo js add one day to a date 
Javascript :: how to download react table into pdf full 
Javascript :: javascript target closest 
Javascript :: file-loader support json file 
Javascript :: How to concatenate two textbox values in JavaScript 
Javascript :: div goind down 
Javascript :: callback hell 
Javascript :: javascript iterable 
Javascript :: js how to sort array by object value 
Javascript :: node js gitignore 
Javascript :: reactjs import electron 
Javascript :: input as html in console 
Javascript :: Fake Binary 
Javascript :: associative array add new key and value js 
Javascript :: lodash group by except group null items 
Javascript :: js any array member true 
Javascript :: custom hook 
Javascript :: express ubuntu ERR_CONNECTION_REFUSED 
Javascript :: Custom delay function for waitfor puppeteer 
Javascript :: how to extract strings in array js 
Javascript :: waypoint 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =