CBSE 8. WEB SCRIPTING - JAVA SCRIPT (5 MARKS)

 16. Searching for Text in a String

JavaScript

<!DOCTYPE html>

<html>

<head>

<title>String Match</title>

</head>

<body>

 

<script>

  var str = "The quick brown fox jumps over the lazy dog";

  var found = str.match(/brown/);

  if (found) {

    document.write("The word 'brown' was found.");

  } else {

    document.write("The word 'brown' was not found.");

  }

</script>

 

</body>

</html>

This searches for the word "brown" in the string and displays a message accordingly.

No comments:

Post a Comment