title: JQuery: how can I push a file to another input array value?
body: <p>I have 2 inputs:</p>
  
  <p>
    </p>
  
  <p>each time, I select some files form <code>temp</code> and I want push to another input <code>files</code>.</p>
  
  <p>I do this step:</p>
  
  <p>chage first iput:</p>
  
  <pre><code>&lt;input type="file" id="temp" name="temp[]" onchange="readFile(this);" multiple /&gt;
  
  function readFile(input) {
      counter = input.files.length;
       for(x = 0; x&lt;counter; x++){
          if (input.files &amp;&amp; input.files[x]) {
             const  reader = new FileReader();
  
             reader.onload = function (e) {
                // add thumbnail picture
             }
  
             reader.readAsDataURL(input.files[x]);
  
          }
       }
  }
  </code></pre>
  
  <p>I add this code to main js fuction:</p>
  
  <pre><code>            var  new_file = [];
              new_file["id"] = "1";
              new_file["main"] = "0";
              new_file["delete"] = "0";
              new_file["file"] = input.files[x];
              files = $("input[name='files[]']").val();
              if(!Array.isArray(files)) files = [];
              files.push(new_file);
              $("input[name='files[]']").val(input[x]);
  </code></pre>
  
  <p>So finall code:</p>
  
  <pre><code>function readFile(input) {
      counter = input.files.length;
       for(x = 0; x&lt;counter; x++){
          if (input.files &amp;&amp; input.files[x]) {
             const  reader = new FileReader();
  
              var  new_file = [];
              new_file["id"] = "1";
              new_file["main"] = "0";
              new_file["delete"] = "0";
              new_file["file"] = input.files[x];
              files = $("input[name='files[]']").val();
              if(!Array.isArray(files)) files = [];
              files.push(new_file);
              $("input[name='files[]']").val(input[x]);
  
             reader.onload = function (e) {
                // add thumbnail picture
             }
  
             reader.readAsDataURL(input.files[x]);
  
          }
       }
  }
  </code></pre>
  
  <p>So I have 2 problem:</p>
  
  <p>in server side, I got this:</p>
  
  <pre><code> "files" =&gt; array:1 [▼
      0 =&gt; null
    ]
  </code></pre>
  
  <p>but temp is ok:</p>
  
  <pre><code>"temp" =&gt; array:1 [▼
      0 =&gt; UploadedFile {#1349 ▶}
   ]
  </code></pre>
  
  <p>Also, in line <code>new_file["file"] = input.files[x];</code>, input.files[x] is not a file. it is an object. how can insert file to new_file["file"]?</p>