Javascript examples for JSon:JSon String
Use array map function to replace value if key is same in json object
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//www . ja va2s .c o m var items = [{"Id":"car","color":"blue"},{"Id":"truck","color":"red"}]; var newItem = {"Id":"car","color":"yellow"}; items.map(function(obj) { (obj.Id === newItem.Id) && (obj.color = newItem.color); }); console.log(items); } </script> </head> <body> </body> </html>