How to update existing object or add new object of an array of objects conditionally using es6 in js