javascript - replace for " " (space) doesn't work -


this question has answer here:

<!doctype html> <html> <body>  <p id="demo">click button locate in string specifed value occurs.</p>  <button onclick="myfunction()">try it</button>  <script> function myfunction() { var =" picture"; a.replace(" ","");   var n=a.indexof(" "); document.getelementbyid("demo").innerhtml= n+a+n; } </script>  </body> </html> 

i replace " "(space) out " picture" in example above

but result seem it's not replace replace command.

the result should "-1picture-1" after replace it's "0 picture0"

with space in front of picture. (i use .indexof(" ") indicate

there space in variable or not -1 mean doesn't )

what's happen?? please advise

replace doesn't modify string in place, returns modified string.

a = a.replace(" ",""); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -