0

I have a very simple script to check if the array contains a link. here is my code:-

var ss = SpreadsheetApp.openById('1MaxxxxxxxxxxxxxxxxxSPg');
  var sheet = ss.getSheetByName('Referral Forms');
  var lastrow = sheet.getLastRow();
  var data = sheet.getRange("L1:L" + lastrow).getDisplayValues();  
  
  var index = data.indexOf(arr.link);

  Logger.log(arr.link)    
  Logger.log(data)
  Logger.log(" index:"+index)

My log shows value is present but its index is showing -1. One thing I noticed that my value contains special characters can that be the reason?

here is a snapshot of my logs:-

Mask
  • 573
  • 7
  • 24

1 Answers1

0

data is a 2-dimensional array. Every element is an array, but arr.link is a string.

You can use map() to unwrap the strings from the arrays.

data = sheet.getRange("L1:L" + lastrow).getDisplayValues().map(x => x[0]);
Barmar
  • 741,623
  • 53
  • 500
  • 612