javascript - Find object in array and then edit it -


let's have following array:

var things = [     {         id: "12345",         name: "bryan"     },     {         id: "55555",         name: "justin"     } ] 

i want search object id of 55555. want update name of particular object "mike" justin still keep entire army intact.

at moment, kinda figured out way search object, can't find solution edit particular finding.

could me out? have far:

var thing = things.filter(function (item) {     return "55555" === item.id; })[0] 

how function finds correct id , changes name

var things = [      {          id: "12345",          name: "bryan"      },      {          id: "55555",          name: "justin"      }  ]    function updatethings(id, value, arr) {      arr.foreach(function(item) {          if (item.id == id) {             item.name = value;             return false;          }      });  }    updatethings("55555", "mike", things);    document.body.innerhtml = '<pre>' + json.stringify(things, null, 4) + '</pre>';


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -