0

I'm trying to create a script to check if all the values in a range of rows are unique usig google app scripts.

function verficarCodUnico(){
  let ss = SpreadsheetApp.getActive();
  let sheet = ss.getActiveSheet();
  let lastRow = sheet.getMaxRows();
  let frozenRows = sheet.getFrozenRows();
  let fCol = sheet.getRange(frozenRows+1,1,lastRow).getValues();
  //this range created with to more lines than it should, so:
  fCol.length = fCol.length -2;
  
  
  let repeated = [];
  let aux = fCol.filter(function(elemento, i) {
    if(fCol.indexOf(elemento) !== i) {
        repeated.push(elemento)
    }
    return fCol.indexOf(elemento) == i;  

this code should work but the fCol array is been created as a array of arrays fCol = [[1],[123],[2],[123]] but what i want is fCol = [1,123,2,123]

I could fix the problem with

let fCol2 = [];
  for (i in fCol){fCol2.push(fCol[i][0])}

I looked in the google app script api, and i undestood that getValues should return the values of the range. Or I am wrong?

print from google app script help page

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Yes, you are wrong :P The referred doc clearly states that `getValues` returns an Array of Arrays (that is the meaning of "a two-dimentional array of values). If you need further help, please add a brief description of your [search](https://stackoverflow.com/search) efforts as is suggested in [ask]. – Rubén Oct 09 '21 at 21:20
  • Sorry, i didn't know that a array of values is a Array of Arrays. thanks anyway – Eduardo Silva Oct 09 '21 at 21:56
  • Although it return 2D array from the function, you can use `array.flat()` method to convert it into 1D array with Javascript method. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat – Kin Siang Oct 10 '21 at 00:00
  • 1
    it's not `array of values`. It's `"two-dimensional" array of values` – TheMaster Oct 10 '21 at 07:31

0 Answers0