Horje
how to check if a string contains a specific word in javascript Code Example
check for substring javascript
const string = "javascript";
const substring = "script";

console.log(string.includes(substring));  //true
check if string contains word nodejs
'a nice string'.includes('nice') //true
'a nice string'.includes('nice', 3) //false
'a nice string'.includes('nice', 2) //true
javascript check if string contains a text substring
stringVariable.includes("Your Text");
how to check if a string contains a specific word in javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id='input'>
<button type="button" onclick='btn()'>Alert</button>


<script>
function btn(){
var input=document.getElementById('input').value;
 
 var subs=[
'name','what','child','all','candy'
 ];
 for (let i = 0; i <subs.length; i++) {
     
     
 
 if(input.includes(subs[i])){
     alert("includes " + subs[i]);
 } 
 else{
   console.log('dosnt include '+ subs[i]);
 }
}
}

</script>
</body>
</html>




Javascript

Related
jquery get value from array of objects Code Example jquery get value from array of objects Code Example
how to add two times in javascript Code Example how to add two times in javascript Code Example
Role based authentication in node js MongoDB Code Example Role based authentication in node js MongoDB Code Example
vue get component hash Code Example vue get component hash Code Example
saveAs method of file-saver in angular Code Example saveAs method of file-saver in angular Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7