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

 

17. Replacing Characters in a String

JavaScript

<!DOCTYPE html>

<html>

<head>

<title>String Replace</title>

</head>

<body>

 

<script>

  var str = "Hello world!";

  var newStr = str.replace("world", "everyone");

  document.write(newStr);

</script>

 

</body>

</html>

This replaces the word "world" with "everyone" in the string.


No comments:

Post a Comment