title: Jquery to check Array before adding TypeID and Filesize If exist add size value ? Dropzone JS
body: <p>I have File type and size of files using Dropzone. I am trying to add in array file type and file sizes because I have to limit file size 5MB per file type here is my code,</p>
  <pre><code>         init: function () {
                      this.on(&quot;addedfile&quot;, function (file) {
  
                          if (file.size &lt; 5 * 1024 * 1024 &amp;&amp; file.type.match('pdf.*')) {
                              alert('File added - ' + file.name + ' - Size - ' + file.size);
                              if (typeof Filecount !== 'undefined' &amp;&amp; Filecount != '') {
                                  Filecount = parseFloat(Filecount + file.size);
                              }
                                  else {
                                  Filecount = parseFloat(file.size);
                              }
  
  
                              var storage = localStorage.getItem('itemList') || '{&quot;items&quot;:[]}';
                              var itemObject = JSON.parse(storage);
                              itemObject[&quot;items&quot;].push({ &quot;FileTypeID&quot;: $('#LKP_DocType').find(&quot;:selected&quot;).val(), &quot;FileTotalSize&quot;: Filecount });
                              localStorage.setItem('itemList', JSON.stringify(itemObject));
                              alert(localStorage.getItem('itemList'));
                          }
                      });
  
                          if (file.size &lt; 5 * 1024 * 1024 &amp;&amp; file.type.match('pdf.*')) {
                              alert('File added - ' + file.name + ' - Size - ' + file.size);
                              if (typeof Filecount !== 'undefined' &amp;&amp; Filecount != '') {
                                  Filecount = parseFloat(Filecount + file.size);
                              }
                                  else {
                                  Filecount = parseFloat(file.size);
                              }
  
  
                              var storage = localStorage.getItem('itemList') || '{&quot;items&quot;:[]}';
                              var itemObject = JSON.parse(storage);
                              itemObject[&quot;items&quot;].push({ &quot;FileTypeID&quot;: $('#LKP_DocType').find(&quot;:selected&quot;).val(), &quot;FileTotalSize&quot;: Filecount });
                              localStorage.setItem('itemList', JSON.stringify(itemObject));
                              alert(localStorage.getItem('itemList'));
  }
  </code></pre>
  <p>In this code I have limitation for File Size and File PDF only. I have LKP_DocType dropdown to select file type. Now from dropdown i will select file type and i can only select max of 5MB files per File type from drop down.</p>
  <p>Later I am adding FileTypeID and File Size in array.</p>
  <p>I want to check if File Type ID alrady exist just replace size value in array other wise if File type is not in Array add value in array</p>
  <p>Hopes for your suggestions</p>
  <p>Thanks</p>