title: How do I copy an array returned by a function into another array in JavaScript?
body: <p>I'm trying to return an array populated inside a function to another array, so I can use the values inside the array for a slideshow.</p>
  
  <p>My code is :</p>
  
  <pre><code>       var flag = 0
      var slideimages = new Array()
      slideimages = readfile()
  
      function readfile(){
      //read data into array x
      flag =1
      return x
      }
  
      if(flag == 1){
      //execute slideshow functions
      }
  
      //slideshow functions definitions (for timeout n picture index etc)
      //using slideimages[index] to choose pic
  </code></pre>
  
  <p>Could anyone help me out here?</p>
  
  <p>My slideshow isn't running, and I'm guessing it's because the values aren't getting copied into the slideimages[]</p>
  
  <p>edit:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;
      &lt;div id="col1"&gt;
                  &lt;img id="img_frame" class="lazy-img" name="slide1"&gt;
              &lt;/div&gt;
              &lt;div id="col2"&gt;
                  &lt;img id="img_frame" class="lazy-img" name="slide2"&gt;
              &lt;/div&gt;
              &lt;div id="col3"&gt;
                  &lt;img id="img_frame" class="lazy-img" name="slide3"&gt;
              &lt;/div&gt;
              &lt;div id="col4"&gt;
                  &lt;img id="img_frame" class="lazy-img" name="slide4"&gt;
              &lt;/div&gt;
              &lt;div id="col5"&gt;
                  &lt;img id="img_frame" class="lazy-img" name="slide5"&gt;
              &lt;/div&gt;    
      &lt;script language="JavaScript1.1"&gt;
                  function getImages() {
                      var slideimages = new Array();
                      slideimages = readfile();
                      if(slideimages){
                          slideit1()
                          slideit2()
                          slideit3()
                          slideit4()
                          slideit5()
                      }
  
                  }
  
                  function readfile(){ 
                      var allText =[];
                      var Lines = [];
                      var txtFile = new XMLHttpRequest();
                      txtFile.open("GET", "urls.txt", true);
                      allText = txtFile.responseText;
                      txtFile.onreadystatechange = function()
                      {
                          if (txtFile.readyState == 4 &amp;&amp; txtFile.status == 200)
                          {// Makes sure it's found the file.
                              allText = txtFile.responseText;
                              Lines = allText.split(/\r\n|\n/);
                          } 
                          else {
                              //alert("Didn't work"); 
                          }
                      }
                      txtFile.send(null)
                      return Lines
                  }
                  var slideshowspeed1=3000
                  var slideshowspeed2=27000
                  var slideshowspeed3=70000
                  var slideshowspeed4=11000
                  var slideshowspeed5=50000  
  
                  var whichimage1=0
                  var whichimage2=100
                  var whichimage3=300
                  var whichimage4=500
                  var whichimage5=700
  
  
  
                  function slideit1(){
                      if (!document.images)
                          return
                      document.images.slide1.src=slideimages[whichimage1]
                      if (whichimage1&lt;slideimages.length-1)
                          whichimage1++
                      else
                          whichimage1=0
                      setTimeout("slideit1()",slideshowspeed1)}//slideit1()
  
  
                  function slideit2(){
                      if (!document.images)
                          return
                      document.images.slide2.src=slideimages[whichimage2]
                      if (whichimage2&lt;slideimages.length-1)
                      whichimage2++
                      else
                          whichimage2=0
                      setTimeout("slideit2()",slideshowspeed2)}//slideit2()
  
                  function slideit3(){
                      if (!document.images)
                          return
                      document.images.slide3.src=slideimages[whichimage3]
                      if (whichimage3&lt;slideimages.length-1)
                      whichimage3++
                      else
                          whichimage3=0
                      setTimeout("slideit3()",slideshowspeed3)}//slideit3()
  
                  function slideit4(){
                      if (!document.images)
                          return
                      document.images.slide4.src=slideimages[whichimage4]
                      if (whichimage4&lt;slideimages.length-1)
                      whichimage4++
                      else
                          whichimage4=0
                      setTimeout("slideit4()",slideshowspeed4)}//slideit4()
  
                  function slideit5(){
                      if (!document.images)
                          return
                      document.images.slide5.src=slideimages[whichimage5]
                      if (whichimage5&lt;slideimages.length-1)
                      whichimage5++
                      else
                          whichimage5=0
                      setTimeout("slideit5()",slideshowspeed5)}//slideit5()
  
              &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I don't really know why the divs on my webpage aren't displaying the images (whose urls are in the urls.txt file). I'm really new to this.</p>