title: Angular 5 - How to build an object with several key's and values
body: <p>Im trying to build an object that is going to have a key and its values:</p>
  
  <pre><code>const codeRed = this.orderInProgressCmsModel.orderStatusColorRed.split(",");
  const codeGreen = this.orderInProgressCmsModel.orderStatusColorGreen.split(",");
  
  const testObj = { colorName: "", colorCodes: []};
  </code></pre>
  
  <p>Im doing the following to add the information to the object itself: </p>
  
  <pre><code>testObj.colorName = "red";
  testObj.colorCodes = codeRed;
  testObj.colorName = "green";
  testObj.colorCodes = codeGreen;
  </code></pre>
  
  <p>Doing it this way though will only add the last two into my object as its overwriting. </p>
  
  <p>The purpose is that im trying to refactor the following code to avoid using so many if's and trying to get the same result with a more logical approach if possible: </p>
  
  <pre><code>if(codeRed.some(s =&gt; s.includes(code))){
    this.orderStatusColor = JSON.parse('{"color": "red"}');
  }
  
  if (codeGreen.some(s =&gt; s.includes(code))){
    this.orderStatusColor = JSON.parse('{"color": "green"}');
  }
  
  if (codeBlack.some(s =&gt; s.includes(code))){
    this.orderStatusColor = JSON.parse('{"color": "black"}'); 
  }
  </code></pre>