Find object in array and change its property if I know its other property

后端 未结 3 936
清歌不尽
清歌不尽 2021-01-26 01:37

I\'ve got an array of objects and I need a function that finds object an array by the objects property (id in example) and changes its other property (name

3条回答
  •  野的像风
    2021-01-26 01:49

    Use this instead of filter. Filter produce new array.

    arrayOfObjects.forEach(function(v){
      if (v.id == id) {v.name = newName}
    });
    

提交回复
热议问题