The indexOf() method How to return the position of the first found occurrence of a specified value in a string.
<html>
<body>
<p id="demo">Click the button to locate where in the string a specifed value occurs.</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
var str="Hello world, welcome to the univers.";
var n=str.indexOf("welcome");
document.getElementById("demo").innerHTML=n;
}
</script>
</body>
</html>
No comments:
Post a Comment