Find and replace object in array (based on id)
问题 Got a bit of a puzzle here...I want to loop through allItems and return allItems but replace with any newItems that matches its id. How can I look for a match on id and then replace it with the correct object into the array? const allItems = [ { 'id': 1, 'category_id': 1, 'text': 'old', }, { 'id': 2, 'category_id': 1, 'text': 'old' } ] const newItems = [ { 'id': 1, 'category_id': 1, 'text': 'new', 'more_info': 'abcd' }, { 'id': 2, 'category_id': 1, 'text': 'new', 'more_info': 'abcd' } ] What