UNPKG

@prorenata/vue-rest-resource

Version:

Rest resource management for Vue.js and Vuex projects

13 lines (10 loc) 303 B
export default function mergeById(originalArray, newData) { const shallowCopy = [...originalArray]; const index = shallowCopy.findIndex((data) => data.id === newData.id); if (index === -1) { shallowCopy.push(newData); } else { shallowCopy[index] = newData; } return shallowCopy; }