Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- items = [{"Id":"car","color":"blue"},{"Id":"truck","color":"red"}]
- newItem = {"Id":"car","color":"yellow"}
- items = [{"Id":"car","color":"yellow"},{"Id":"truck","color":"red"}]
- for (var i=0; i<items.length; i++)
- {
- var x = items[i];
- if(x.Id == newItem.Id){ //first check if id matches
- if (JSON.stringify(items[i]) == JSON.stringify(newItem)) {
- alert('objects are same');
- return ;
- }
- else {
- var newColor = JSON.stringify(x).replace(x.color, newItem.color);
- alert(JSON.parse(newColor));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement