check for substring javascript
const string = "javascript";
const substring = "script";
console.log(string.includes(substring)); //true
check for substring javascript
const string = "javascript";
const substring = "script";
console.log(string.includes(substring)); //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>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us