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

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -