title: Javascript - Split and return array in multiple arrays or string
body: <p>I have a json like this:</p>
  
  <pre><code>{"search":{"updated":"2018-11-07","name":[{"tag":"Peter"}]}}
  </code></pre>
  
  <p>... and I dynamically fetch the values and create a variable this: </p>
  
  <pre><code>var existingParams = [
  "name",
  "updated"].filter(field =&gt; getBody.search[field]);
  
  var sqlVal = existingParams.map(field =&gt; {
   if (field === 'name') {
       function getValues(item, index) {
         var getVal = [item.tag];
         return "%" + getVal + "%";
       }
       console.log(name.map(getValues));
       return name.map(getValues);
  
     } else {
       return getBody.search[field];
     }
   })
  </code></pre>
  
  <p>For the above example I get for sqlVal:</p>
  
  <pre><code>console.log(sqlVal);         
  
  [ [ '%Peter%' ], '2018-11-07' ]
  </code></pre>
  
  <p>... which is fine. </p>
  
  <p>BUT, if I have two values:</p>
  
  <pre><code>{"search":{"updated":"2018-11-07","name":[{"tag":"Peter"},{"tag":"Jack"}]}} 
  </code></pre>
  
  <p>... I'm getting this structure:</p>
  
  <pre><code>[ [ '%Peter%', '%Jack%' ], '2018-11-07' ]   
  </code></pre>
  
  <p>... but what I need is sth like:</p>
  
  <pre><code>[ '%Peter%', '%Jack%', '2018-11-07' ]
  </code></pre>
  
  <p>... or:</p>
  
  <pre><code>[ ['%Peter%'], ['%Jack%'], '2018-11-07' ]
  </code></pre>
  
  <p>And in case of further e.g. 3 names:            </p>
  
  <pre><code>{"search":{"updated":"2018-11-07","name":[{"tag":"Peter"},{"tag":"Jack"},{"tag":"Maria"}]}} 
  </code></pre>
  
  <p>... I need sth like:    </p>
  
  <pre><code>[ '%Peter%', '%Jack%', '%Maria%', '2018-11-07' ]        
  </code></pre>
  
  <p>... or:</p>
  
  <pre><code>[ ['%Peter%'], ['%Jack%'], ['%Maria%'], '2018-11-07' ]
  </code></pre>
  
  <p>... and so on</p>
  
  <p>How do I need to adjust the above query to get this?</p>