I am learning Javascript and have a quick question. I want to search a string for a specific word or phrase. If that word/phrase exists in the the string. I want to save it to a variable to be used later.
Code I have so far is as follows:
var str = "This is a test sentence";
var hasTest = str.includes("test");
if(hasTest == true)
{
//save the word that was searched
}
Aucun commentaire:
Enregistrer un commentaire