title: How to group the array string in to object by matching?
body: <p>I would like to group an array of strings into an object. how to do this? Is there any easier way to do this?</p>
  
  <p>This is what I expect:</p>
  
  <pre><code>// I want to convert this:
  var mandate = ["sender.state","sender.city", "sender.postalcode", 
    "receiver.state", "receiver.city", "receiver.postalcode"];
  
  // To this:
  var groups = {
   'group1' : ["sender.state","sender.city", "sender.postalcode"],
   'group2' : ["receiver.state", "receiver.city", "receiver.postalcode"]
  }
  </code></pre>
  
  <p>Here is my try:</p>
  
  <pre><code>var groups = {
   'group1' : [],
   'group2' : []
  }
  
  var mandate = ["sender.state","sender.city", "sender.postalcode", "receiver.state", "receiver.city", "receiver.postalcode"];
  
  for( let name in mandate ){
      if( mandate[name].indexOf('sender') ){
      groups.group1.push(mandate[name])
    }
    if( mandate[name].indexOf('receiver') ){
      groups.group1.push(mandate[name])
    }
  }
  
  console.log( groups );
  </code></pre>