string replace javascript/jquery
[{"fi开发者_运维问答eld":"Comment","message":"Message cannot be empty"}]
In the above string i want to replace the word comment. I dont wish to use any other external libraries expect jquery
Suppose you're talking about array object:
var array = [{"field":"Comment","message":"Message cannot be empty"}];
Then what you need is:
array[0]["field"] = "other value comes here";
Live test case: http://jsfiddle.net/yahavbr/7Xgwk/
(Click "View", click "Change" and click "View" again)
javaScript replace() Method
Example code :
<script type="text/javascript">
var str="Visit Microsoft!";
document.write(str.replace(/microsoft/i, "W3Schools"));
</script>
精彩评论