We need all two test cases can be came when code was run. I want exact outputs for all two test cases.Check Whether the input string includes the substring using if condition and includes().
if the input string includes the substring then,
Find the index of the substring in the input string, using the indexof() and store the index in a variable.
slice the input string, using the slice() form index to the length of the input string and store in the variable slicedString.
const slicedString = inputString.slice(index, inputString.length);
if the input string doesn't include the substring then else console the input string.
<script>
// Sample string
var str = "The quick brown fox jumps over the lazy dog."
// Check if the substring exists inside the string
var index = str.indexOf("fox");
if(index !== -1){
alert("Substring found!");
} else{
alert("Substring not found!");
}
</script>
Comments
Leave a comment