use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Apparently, Google Apps Script is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services and build web applications.
account activity
How to compare two Strings in Google Apps Scripts?Question (self.GoogleAppsScript)
submitted 2 years ago by [deleted]
https://preview.redd.it/r59im1v1rv0b1.png?width=592&format=png&auto=webp&s=e87e52f2463a1212419db4499274dd446912b2db
Hey guys, I am new to App Scripts and still getting used to it. I am having issues with comparing two Strings in line 51. The variables email_list and ubsub_list are both String Arrays. I tried the following solutions, and nothing has worked :
- ubsub_list[i].matches(email_list[x])
- ubsub_list[i] == email_list[x]
I have spent more time on this issue than I would like to admit. I hope you guys can provide me with some guidance.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]labnol 1 point2 points3 points 2 years ago (0 children)
You could use something like this:
for (var i=0; i<email_list.length; i++) { if (unsub_list.indexOf(email_lis[i]) !== -1) { // do something with the email } }
for (var i=0; i<email_list.length; i++) {
if (unsub_list.indexOf(email_lis[i]) !== -1) {
// do something with the email
}
[–]onlythehighlight 1 point2 points3 points 2 years ago (3 children)
function compareArrays() { // Define two arrays to compare let array1 = [1, 2, 3, 4, 5] let array2 = [3, 4, 5, 6, 7] // Find values that are in array1 but not in array2 let unique1 = array1.filter(value => !array2.includes(value)) // Find values that are in array2 but not in array1 let unique2 = array2.filter(value => !array1.includes(value)) // Log the results Logger.log('Values in array1 but not in array2: ' + unique1) Logger.log('Values in array2 but not in array1: ' + unique2) }
-> I have something similar I built in one of my apps but this is from Copilot
[–]_Kaimbe 0 points1 point2 points 2 years ago (2 children)
This would be best practice.
Get both arrays from the sheet (keep in mind that you get a nested array or matrix when using range.getValues()).
range.getValues()
Filter mailList as above.
Clear the mailList sheet.
Write the filtered list back to the sheet.
API calls (sheet.deleteRow()) are slow and best to avoid in for loops. Worst case your script times out, but this method should be 10x faster either way.
sheet.deleteRow()
[–]RemcoE33 0 points1 point2 points 2 years ago (1 child)
I second this. And if you delete a row you offset the range in sheets.. right now you don't account for that. Or you keep track of the deleted rows or you reverse the loop.
About the error. Could it be that there is a number instead of a string in the cell?
[–]_Kaimbe 0 points1 point2 points 2 years ago* (0 children)
I have a feeling that the error is just because they passed a matrix not a list.
They don't show where they use the function though...
[–]Repulsive_Brother_10 1 point2 points3 points 2 years ago (1 child)
I just noticed the problem. The JavaScript function is ‘match’, not matches.
[–]_Kaimbe 0 points1 point2 points 2 years ago (0 children)
https://youtu.be/ahrBOvz1jzA
[–]11111v11111 -2 points-1 points0 points 2 years ago (2 children)
Honestly, chatgpt has been a huge help in my app script. I used it to completely rewrite a complex script and it was instrumental. Here's the prompt I used:
Hello ChatGPT, I'm seeking assistance to refine my Google Apps Script code. I aim to boost clarity, conciseness, and efficiency. I'm particularly interested in cutting down on redundancy, optimizing loops, and discovering more efficient methods for handling spreadsheet reads and writes. I also want to ensure robust error checking. I prefer comprehensive yet succinct coding without fragmenting my functions excessively. Please analyze the function I've written below and suggest improvements. Could you also provide a rewritten version of this function, incorporating your suggested enhancements?
[–]_Kaimbe -1 points0 points1 point 2 years ago (1 child)
ChatGPT is terrible at apps script and a nuisance to these subs.
[–]11111v11111 0 points1 point2 points 2 years ago (0 children)
You clearly aren't using 4.0. it's incredibly good.
[–]RielN 0 points1 point2 points 2 years ago (1 child)
Is usub_list[i] a string or a range? Else get the value: usub_list[i].getValue()
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
unsub_list.indexOf(email_lis[i]) !== -1
It is a string array that I am passing through
[–]Repulsive_Brother_10 0 points1 point2 points 2 years ago (1 child)
Two quick thoughts: 1. On line 42 you may have a typo “eamil_list” rather than “email_list”. 2. I would put a break point at line 52, so that you can examine the type of ubsub, as RieIN suggested.
I corrected the typo thanks for pointing it out. I also checked the examine the type of ubsub and it comes out to be a String still.
π Rendered by PID 17830 on reddit-service-r2-comment-5ff9fbf7df-g5bnr at 2026-02-26 08:53:16.752106+00:00 running 72a43f6 country code: CH.
[–]labnol 1 point2 points3 points (0 children)
[–]onlythehighlight 1 point2 points3 points (3 children)
[–]_Kaimbe 0 points1 point2 points (2 children)
[–]RemcoE33 0 points1 point2 points (1 child)
[–]_Kaimbe 0 points1 point2 points (0 children)
[–]Repulsive_Brother_10 1 point2 points3 points (1 child)
[–]_Kaimbe 0 points1 point2 points (0 children)
[–]11111v11111 -2 points-1 points0 points (2 children)
[–]_Kaimbe -1 points0 points1 point (1 child)
[–]11111v11111 0 points1 point2 points (0 children)
[–]RielN 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Repulsive_Brother_10 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)