title: how to remove everything after a particular string from an array of strings in javascript
body: <p>I have an array of strings from which I want to remove anything after <code>with</code> in the statement.
  For example, let's take a string</p>
  <pre><code>var str = ['hey what is with you guys',
  'you mean with out', 
  'hello no with is you']
  
  </code></pre>
  <p>the new str2 should return</p>
  <pre><code>['hey what is', 
  'you mean' ,
  'hello no'
  ] 
  
  </code></pre>
  <p>I have written the following code but it is not giving the desirable output.
  My code:</p>
  <pre><code>function newArray(str){
      for (var i = 0; i &lt;= (str.length - 1); i++){
          var k = str[i].toString()
          j = k.split('with')
          var arr2 = []
          var newArr = arr2.concat(j[0])
          console.log(newArr)
          
      }
      return newArr
  }
  
  
  var str = ['hey what is with you guys',
  'you mean with out', 
  'hello no with is you']
  
  newArray(str)
  
  </code></pre>
  <p>the output is</p>
  <pre><code>[ 'hey what is ' ]
  [ 'you mean ' ]
  [ 'hello no ' ]
  
  </code></pre>
  <p>However, I want my output</p>
  <pre><code>['hey what is', 
  'you mean' ,
  'hello no'
  ] 
  </code></pre>