title: Can't sort array passed as argument into function (TypeError, cannot call method sort of undefined)
body: <p>I'm writing a script for sheets using Google Apps script, and I'm passing an array as an argument into a function, and I'd like to sort the array inside, and return a new array that's also been manipulated a bit after it's been sorted. I took some code from another thread <a href="https://stackoverflow.com/questions/25735677/remove-duplicates-values-in-array-google-apps-script">here</a></p>
  <p>The code:</p>
  <pre><code>function removeDupes(array) {
    var outArray = [];
    array.sort(); //sort incoming array according to Unicode
    outArray.push(array[0]); //first one auto goes into new array
    for(var n in array){ //for each subsequent value:
      if(outArray[outArray.length-1]!=array[n]){ //if the latest value in the new array does not equal this one we're considering, add this new one. Since the sort() method ensures all duplicates will be adjacent. V important! or else would only test if latestly added value equals it.
        outArray.push(array[n]); //add this value to the array. else, continue.
      }
    }
    return outArray;
  }   
  </code></pre>
  <p><code>array.sort();</code> returns the error</p>
  <blockquote>
  <p>&quot;TypeError: Cannot call method &quot;sort&quot; of undefined. (line 91, file
  &quot;Code&quot;)&quot;</p>
  </blockquote>
  <p>. How can I perform the sort() method on the array passed into this function as an argument?</p>