javascript - replace for " " (space) doesn't work -
this question has answer here:
- replace.() not work 3 answers
<!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(" ","");