title: apply css by checking if value exists
body: <p>I have an array with objects inside. What I'm trying to do is loop through the array and check if a value exists by key and if it does apply a CSS to a div but right now even though the value exists the specified CSS doesn't apply it just applies the &quot;else&quot; CSS. Why is this happening and how can I fix it? Thanks in advance.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let testArray = [{"length": "None", "duration": "10000", "percentage": "65"}, {"width": "Half", "detail": "under", "duration": "25000", "percentage": "25"}, {"length": "Full", "duration": "20000", "percentage": "90"}]
  
  testArray.forEach((obj) =&gt; {
    if (obj.length?.toLowerCase() == 'none') {
      $('.test').css('background-color', 'red')
    } else {
      $('.test').css('background-color', 'blue')
    }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.test {
    width: 30%;
    height: 40%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class='test'&gt;
    &lt;p&gt;testing&lt;/p&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>