Try
items[id] = items[id] || {}; //Does the same work as the if statement
instead of items.id
. With this you can assign dynamic properties.
(Trust me, I had the same problem once.)
Or you can use Object.defineProperty(obj, prop, descriptor)
(a little bit different).
Quoting the documentation:
The Object.defineProperty() method defines a new property directly on an object
or modifies an existing property on an object, and returns the object.
Check out more in Object.defineProperty().
These are two ways of doing the trick. Clearly the second one is a little bit different from the first one that is simpler.