title: JavaScript loop through to check duplicate value
body: <p>I am having troubles trying to check if the date exists in the array.</p>
  
  <pre><code> for(var i = 0; i&lt; crisislist.length; i++){
          hazecounter = 1;
          if(crisislist[i].category == 1){
              if(crisislist[i].date != crisislist[i+1].date) {
                  hazelabel.push(crisislist[i].date);
              }else{
                  hazecounter++; 
              }
              hazedata.push(hazecounter);
          }
   }
  </code></pre>
  
  <p>The sample data for the date is:</p>
  
  <pre><code>["01-02-2017", "22-03-2017", "22-03-2017", "07-08-2017"]
  </code></pre>
  
  <p>And the expected output for hazelabel, hazedata should be:</p>
  
  <p>hazelabel: ["01-02-2017", "22-03-2017", "07-08-2017"]
     hazedata: [1,2,1]</p>
  
  <p>With the code above, when I check until the last element in the array and trying to make a comparison, it throw me an error message:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'date' of undefined
  </code></pre>
  
  <p>I think this is because when I reach the last element of array, and I try to find crisislist[I+1].date, it could not found and thus the error message.</p>
  
  <p>Any idea how to fix this? Thanks in advance!</p>