title: JavaScript - using if statement in append()
body: <p>I use this in a loop:</p>
  
  <pre class="lang-js prettyprint-override"><code> $(".somediv").append('text' + array[key].arrayelement + 'sometext'+ array[key].nextelementinArray + 'moretext']);
  </code></pre>
  
  <p>How do I implement this: if <code>array[key].arrayelement</code> is <code>null</code> (yeah, it can be only text <code>'null'</code>), then do one thing, and if notm, then another thing?</p>
  
  <p>I tried this appendable text to make 2 variables, but it did not work.</p>
  
  <pre><code>card.append('&lt;div class="col-sm-12 col-md-6 col-lg-4"&gt;&lt;div class="info-block bg-grey m-b-2 p-a-2"&gt;&lt;h4 class="h4 underline-sm"&gt; ' + response[key].firstname + ' ' + response[key].lastname + ' '  + '&lt;/h4&gt;&lt;div class="col-sm-8 text-xs-left"&gt;                        &lt;p class="m-b-1"&gt;&lt;b&gt;'+ response[key].job_title + '&lt;br&gt;Tööruum:' + $.trim(response[key].room) + '&lt;/b&gt;&lt;/p&gt;&lt;a href="mailto:' + $.trim(response[key].email) + '"&gt;' + $.trim(response[key].email) + '&lt;/a&gt;&lt;p class="m-b-0"&gt;' + $.trim(response[key].phone) + ' ' + $.trim(response[key].cell_phone) + '&lt;/div&gt;&lt;div class=" col-sm-4 text-xs-right m-b-1"&gt;&lt;img src="' + $.trim(response[key].image) + '" class="rounded-circle lg" alt=""&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;');
  </code></pre>
  
  <p>Simple i get: But i dont want to see </p>
  
  <pre><code>Tööruum: ' + response[key].room
  </code></pre>
  
  <p>when the room value is text 'null'. I tried this inside append, where is this response[key] room. </p>
  
  <pre><code>`function(){if(response[key].room===null) {return " ";}else {return '&lt;br&gt;Tööruum: + response[key].room';}};
  </code></pre>
  
  <p>but nada.</p>