String replace in javascript -
so have string var total_res = r4-4r4-5;
, want replace r4-5
substring ""
,but have tried code far , doesn't work:
javascript:
<script> $(document).ready(function(){ ss = "r4-5"; lool = total_res.replace(ss,""); alert(lool);//it alerts same original string }); </script>
what wrong? thank help.
i'm not sure if meant or not, total_res
should declared string...like:
var total_res = "r4-4r4-5";
using code, works that:
if checked browser's (error) console, you'd see: unexpected token illegal
.
note .replace()
replaces first occurrence of string. you'd have use regular expression if want replace every occurrence of "r4-5" in string.
Comments
Post a Comment