how to update an object in array if exists other wise add it as a new object in the array in javascr