title: Adding Array from Variable on Google Sheets - Google Apps Script
body: <p>I have an existing code which looks like,</p>
  
  <pre><code>var copyPageNumbers = [5, 7, 9];
  </code></pre>
  
  <p>I have the same number 5, 7, 9 in a column on my google sheet and have set up a variable to get value,</p>
  
  <pre><code>var credentials = ss.getRange(i, 11).getValue(); // The value of this is 5, 7, 9
  </code></pre>
  
  <p>Based on the variables above. I want to use a code which uses the <code>credentials</code> variable in the <code>copyPageNumbers</code> variable to look something like this,</p>
  
  <pre><code>var copyPageNumbers = [credentials];
  </code></pre>
  
  <p>For example, the below chunk of code works, </p>
  
  <pre><code>  var credentials = ss.getRange(i, 11).getValue();
    var copyPageNumbers = [2, 4];
  
    var offset = 1;
  
    var slides = otherPresentation.getSlides();
    var page = 0;
    slides.forEach(function(slide, i) {
      if (copyPageNumbers.indexOf(i + 1) != -1) {
        currentPresentation.insertSlide(offset + page, slide);
        page++;
      }
    });
  </code></pre>
  
  <p>However when I try both the methods stated below - it doesnt work,</p>
  
  <pre><code>  var credentials = ss.getRange(i, 11).getValue().split(", ");
    var copyPageNumbers = credentials
    var offset = 1;
    var slides = otherPresentation.getSlides();
    var page = 0;
    slides.forEach(function(slide, i) {
      if (copyPageNumbers.indexOf(i + 1) != -1) {
        currentPresentation.insertSlide(offset + page, slide);
        page++;
      }
    });
  </code></pre>
  
  <pre><code>  var credentials = ss.getRange(i, 11).getValue();
    var offset = 1;
    var copyPageNumbers = []
    copyPageNumbers.push(credentials);
    var slides = otherPresentation.getSlides();
    var page = 0;
    slides.forEach(function(slide, i) {
      if (copyPageNumbers.indexOf(i + 1) != -1) {
        currentPresentation.insertSlide(offset + page, slide);
        page++;
      }
    });
  </code></pre>