title: Javascript convert comma seperated string of words to key value objects in array
body: <p>I need to convert a list of email to a key value object within an array. I start with <code>&quot;email@mail.com,mike@example.com,john@gmail.com&quot;</code> and I want to end up with</p>
  <pre class="lang-json prettyprint-override"><code>[
     {&quot;to&quot;: &quot;email@mail.com&quot;},
     {&quot;to&quot;: &quot;mike@example.com&quot;},
     {&quot;to&quot;: &quot;john@gmail.com&quot;}
  ]
  </code></pre>
  <p>Here's what I've tried</p>
  <pre class="lang-js prettyprint-override"><code>var req = {
    query: {
      personalize:
        &quot;email@mail.com,mike@example.com,john@gmail.com&quot;
    }
  };
  var emailList = req.query.personalize;
  var emailArr = emailList.split(&quot;,&quot;);
  var emailObj = Object.assign({}, emailArr);
  console.log(emailObj);
  </code></pre>
  <p>Here's what I ended up with</p>
  <pre class="lang-bash prettyprint-override"><code>&quot;0&quot;: &quot;email@mail.com&quot;
  &quot;1&quot;: &quot;mike@example.com&quot;
  &quot;2&quot;: &quot;john@gmail.com&quot;
  </code></pre>
  <p>After this I tried this one</p>
  <pre class="lang-js prettyprint-override"><code>var req = {
    query: {
      personalize:
        &quot;email@mail.com,mike@example.com,john@gmail.com&quot;
    }
  };
  var emailList = req.query.personalize;
  var arr = emailList.split(&quot;,&quot;);
  const res = arr.reduce((acc,curr)=&gt; (acc[curr]='to',acc),{});
  console.log(res)
  </code></pre>
  <p>This got me close, but backwards for what I wanted. Yielding a result like</p>
  <pre class="lang-bash prettyprint-override"><code>&quot;email@mail.com&quot;: &quot;to&quot;
  ...
  </code></pre>