<!DOCTYPE html>
<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>
function myFunction()
{
var a =" picture";
a.replace(" ","");
var n=a.indexOf(" ");
document.getElementById("demo").innerHTML= n+a+n;
}
</script>
</body>
</html>
I would like to replace " "(Space) out from the " picture" in the example above
but the result seem it's not replace by the replace command.
The result should be "-1picture-1" after replace but it's "0 picture0"
with a space in front of picture. (I use .indexOf(" ") to indicate that
there are a space in the variable or not -1 mean it doesn't )
What's it happen?? Please advise