title: Why is the old content of the array deleted?
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let sentenceArr = [['Teachers', 'are', 'clever.'], ['Developers', 'are', 'more', 'clever,', 'because', 'of', 'her', 'practice', 'experience.']];
  
  for(let i=0; i&lt;sentenceArr.length;i++){
      console.log('loop: ' + i +1);
      splitPunctuationMarks(sentenceArr[i]);
  }
  
  
  function splitPunctuationMarks(inSentence_As_Arr){
      let punctuationMarks = ['.', '!', '?', ',', ';', ':'];
      let containsPunctuationMark = (-1);
      let splitParts = [];
      let parts = [];
  
      for(let i=0; i &lt; inSentence_As_Arr.length; i++){
          for(let j=0; j&lt; punctuationMarks.length; j++){
              containsPunctuationMark = inSentence_As_Arr[i].indexOf(punctuationMarks[j]);
              if(containsPunctuationMark &gt;= 0){
                  console.log('### splitPunctuationMarks ' + inSentence_As_Arr[i]);
                  console.log('parts 1: ');
                  console.log(parts);
                  parts[0] = i;
                  parts[1] = inSentence_As_Arr[i].slice(0, containsPunctuationMark);
                  parts[2] = inSentence_As_Arr[i].slice(containsPunctuationMark);
                  console.log('parts 2: ');
                  console.log(parts);
  
                  console.log('splitParts1: ');
                  console.log(splitParts);
  
                  splitParts.push(parts);
  
                  console.log('splitParts2: ');
                      console.log(splitParts);
  
                  containsPunctuationMark = (-1);
                  //parts = [];
              }
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I wrote a function that works in another way than I expect. </p>
  
  <p>I also found a solution, that delivers the result I want. Now I would like to understand, what's wrong with my expectation.</p>
  
  <p>That's my code:</p>
  
  <pre><code>let sentenceArr = ['Teachers are clever.', 'Developers are more clever, because of her practice experience.'];
  
  for(let i=0; i&lt;sentenceArr.length;i++){
      console.log('loop: ' + i +1);
      splitPunctuationMarks(sentenceArr[i]);
  }
  
  function splitPunctuationMarks(inSentence_As_Arr){
      let punctuationMarks = ['.', '!', '?', ',', ';', ':'];
      let containsPunctuationMark = (-1);
      let splitParts = [];
      let parts = [];
  
      for(let i=0; i &lt; inSentence_As_Arr.length; i++){
          for(let j=0; j&lt; punctuationMarks.length; j++){
              containsPunctuationMark = inSentence_As_Arr[i].indexOf(punctuationMarks[j]);
  
              if(containsPunctuationMark &gt;= 0){
                  console.log('### splitPunctuationMarks ' + inSentence_As_Arr[i]);
                  console.log('parts 1: ');
                  console.log(parts);
                  parts[0] = i;
                  parts[1] = inSentence_As_Arr[i].slice(0, containsPunctuationMark);
                  parts[2] = inSentence_As_Arr[i].slice(containsPunctuationMark);
                  console.log('parts 2: ');
                  console.log(parts);
  
                  console.log('splitParts1: ');
                  console.log(splitParts);
  
                  splitParts.push(parts);
  
                  console.log('splitParts2: ');
                  console.log(splitParts);
  
                  containsPunctuationMark = (-1);
                  //parts = [];
              }
          }
      }
  }
  </code></pre>
  
  <p>What I have expected:</p>
  
  <p>1st loop:</p>
  
  <p>'### splitPunctuationMarks clever.</p>
  
  <p>parts1: [ ] //because the empty array has not been filled yet.</p>
  
  <p>parts2: [2, 'clever', '.'] //because that are the tracked data from the first sentence.</p>
  
  <p>splitParts1: [ ] //because the empty array has not been filled yet.</p>
  
  <p>splitParts2: [2, 'clever', '.'] //because that are the data from parts</p>
  
  <p>2nd loop:</p>
  
  <p>'### splitPunctuationMarks clever,</p>
  
  <p>parts1: [ ] //because the empty array has not been filled yet.</p>
  
  <p>parts2: [3, 'clever', ','] //because that are the tracked data from the second sentence.</p>
  
  <p>splitParts1: [ ] //because the empty array has not been filled yet.</p>
  
  <p>splitParts2: [3, 'clever', ','] //because that are the data from parts</p>
  
  <p>'### splitPunctuationMarks  experience.</p>
  
  <p>parts1: [3, 'clever', ','] //because the array has not been overwritten yet.</p>
  
  <p>parts2: [8, 'experience', '.'] //because that are the tracked data from the second sentence.</p>
  
  <p>splitParts1: </p>
  
  <p>I have expected: [3, 'clever', ','] //because of the first pushed content to the array</p>
  
  <p>But I get: [8, 'experience', '.'] //that's what I don't understand</p>
  
  <p>splitParts2: </p>
  
  <p>I have expected: [[3, 'clever', ','], [8, 'experience', '.']]</p>
  
  <p>But I get: [[8, 'experience', '.'], [8, 'experience', '.']] </p>
  
  <p>Why have I lost the first entry of my 2nd loop?</p>