I have two javascript variables. One contains a content object and the other an array of content objects. If the contents object already has contents then I can do a push and add to it. I have this working okay in the first part of my if statement.
However if the contents object is null then the push does not work. How can I make it so that I can add just one content to the null contents object. In other words how can I create a contents object and assign self.content to it in the same time. I have tried here but it is not working:
if (self.contents) {
self.contents.push(self.content);
} else {
self.contents = [self.content]
}