title: How to map over an array of objects to extract values corresponding to keys that start with a prefix?
body: <p>I have an array of objects that looks like that:</p>
  <pre class="lang-js prettyprint-override"><code>const myArr = [
    {id: 1,
    some_data: {
      &quot;color_1&quot;: {
        &quot;value&quot;: &quot;red&quot;
      },
      &quot;color_2&quot;: {
        &quot;value&quot;: &quot;blue&quot;
      },
      &quot;color_3&quot;: {
        &quot;value&quot;: &quot;yellow&quot;
      },
      &quot;shape_1&quot;: {
        &quot;value&quot;: &quot;square&quot;
      },
      &quot;shape_2&quot;: {
        &quot;value&quot;: &quot;circle&quot;
      }
    }
    },
    {id: 2,
       some_data: {
      &quot;color_1&quot;: {
        &quot;value&quot;: &quot;pink&quot;
      },
      &quot;color_2&quot;: {
        &quot;value&quot;: &quot;orange&quot;
      },
      &quot;color_3&quot;: {
        &quot;value&quot;: &quot;yellow&quot;
      },
      &quot;shape_1&quot;: {
        &quot;value&quot;: &quot;square&quot;
      },
      &quot;shape_2&quot;: {
        &quot;value&quot;: &quot;triangle&quot;
      }
    }
    },
    {id: 3,
    /* some_data: {...}*/},
    {id: 4,
    /* some_data: {...}*/}
  ]
  </code></pre>
  <p>I want to go over <code>myArr</code> and extract the values that correspond to colors, to end up with this array:</p>
  <pre class="lang-js prettyprint-override"><code>// desired output
  [&quot;red&quot;, &quot;blue&quot;, &quot;yellow&quot;, &quot;pink&quot;, &quot;orange&quot;, &quot;yellow&quot;]
  </code></pre>
  <p>So I figured out that I would need to use <code>String.prototype.startsWith()</code> on the <em>keys</em>. Unfortunately, I have been unsuccessful in all my attempts to map over <code>myArr</code>.</p>
  <p>Inspired by <a href="https://stackoverflow.com/a/58007707/6105259">this</a> answer I tried:</p>
  <pre class="lang-js prettyprint-override"><code>const oneAttempt = myArr.map((obj) =&gt;
          Object.keys(obj.some_data)
              .filter((v) =&gt; v.startsWith('color'))
              .map((e) =&gt; obj.some_data[e].value)
      );
  </code></pre>
  <p>But it's not quite what I need. It's probably a pretty simple thing but I'm failing to figure this out.</p>