title: Javascript array push only if value not null
body: <p>I'm wondering if, and if how the following thing is working:</p>
  
  <p>I have an array defined like the following:</p>
  
  <pre><code>var array = [
    {number: '1', value: 'one', context: 'someContext'}, 
    {number: '2', value: 'two', context: 'anotherContext'},
    ...
  ]
  </code></pre>
  
  <p>What I'm currently doing is pushing the elements into the array, so <code>array.push({number: '1', value: 'one', context: 'someContext'});</code> and so on, with every array element. </p>
  
  <p>Now this thing is extended: Say there's another key called 'content'. This key has a appropriate value, that is either undefined or a string. Now the question is: If I put the pushing in a function like this:</p>
  
  <pre><code>push(number, value, context, content) {
      array.push({
         number: number,
         value: value,
         context: context,
         content: content
      })
  }
  </code></pre>
  
  <p>Is there anyway, I can make sure, that the key content is only added to the element, if the content (the function gets as parameter) is not null. </p>
  
  <p>Of course I can modify function like that:</p>
  
  <pre><code>push(number, value, context, content) {
      if(!content) {
          array.push({
             number: number,
             value: value,
             context: context,
             content: content
         })
      } else {
          array.push({
             number: number,
             value: value,
             context: context
          })
     }
  }
  </code></pre>
  
  <p>But the question is, if there is anyway to do this in the push function. I also thought about something like</p>
  
  <pre><code>array.push({
    number: number,
    value: value,
    context: context,
    content? content: content
  })
  </code></pre>
  
  <p>So it would only be inserted if content is defined, but does this work, it didn't seem like, but maybe theres a mistake in my code.</p>