String Slicing
Given two strings
inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.
function stringSlicing(){
const string = prompt('Please input string');
const sub = prompt('Please input sub string');
const indexSub = string.indexOf(sub);
if(indexSub !== -1){
return string.slice(indexSub)
} else {
return string
}
}
alert(stringSlicing());
Comments
Leave a comment