title: Javascript: Map values of two arrays in a new array
body: <p>I have two arrays of objects, that look like this:</p>
  
  <pre><code>const data = [
    {
      id: 1,
      condition: 1,
      helpers: [{id: 1, condition: null}, {id: 2, condition: 2}]
    },
    {
      id: 2,
      condition: null,
      helpers: [{id: 1, condition: 1}, {id: 2, condition: null}]
    }
  ]
  
  const conds = [
    {
      id: 1,
      conditions: {
         rules: ['test', 'foo']
      }
    },
    {
      id: 2,
      conditions: {
         rules: ['#hashtag', 'foo']
      }
    }
  ]
  </code></pre>
  
  <p>What I try to achieve is, that I want to replace the <code>condition</code> values of the <code>data</code> array with the ones in the <code>conds</code> array.</p>
  
  <p>My solution, which does not work quite well looks like this:</p>
  
  <pre><code>let newArray = [];
  
  data.forEach(obj =&gt; {
          conds.forEach(cond =&gt; {
              if (obj.condition) {
                  if (obj.condition === cond.id) {
                      obj.condition = cond.conditions.rules;
                      newArray.push(obj);
                  }
              } else {
                  obj.helpers.forEach(h =&gt; {
                      if (h.condition &amp;&amp; h.condition === cond.id) {
                          h.condition = cond.conditions.rules;
                          newArray.push(obj);
                      }
                  });
              }
          })
      });
  </code></pre>
  
  <p>I feel like I am pretty close to the solution since my <code>newArray</code> contains the changes properties, but not for the last item inside of helpers, whereas the <code>condition</code> property is still 2.</p>
  
  <p>The output should look like this:</p>
  
  <pre><code>[
    {
       id: 1
       condition: ['test', 'foo'],
       helpers: [{id: 1, condition: null}, {id: 2, condition: ['#hashtag', 'foo']}]
    },
    {
       id: 2
       condition: null,
       helpers: [{id: 1, condition: ['test', 'foo']}, {id: 2, condition: null}]
    },
  ]
  </code></pre>
  
  <p>What am I missing here?</p>