0

Instead of "var instance = ..." adding the two values it concatenates them. Can anyone suggest what I need to fix?

I'm trying to add "var startingEmail" value and "var k".

Thank you for your help!

 var startingEmail = sheet.getRange("C2").getDisplayValue();
 var numEmails = sheet.getRange("E2").getDisplayValue();



 var max = numEmails;



 for (var k = 0; k<max; ++k){



 var threads = GmailApp.getInboxThreads(startingEmail,max)[k]; //get max 50 threads starting at most recent thread
 var messages = threads.getMessages()[0];

       var sndr; 
       var rcpnt;
       var srAry = [];



       var sndr = messages.getFrom().replace(/^.+<([^>]+)>$/, "$1"); //http://stackoverflow.com/questions/26242591/is-there-a-way-to-get-the-specific-email-address-from-a-gmail-message-object-in      
       var sndrLower = sndr.toLowerCase;

       var rcpnt = messages.getTo().replace(/^.+<([^>]+)>$/, "$1");
       var rcpntLower = rcpnt.toLowerCase;

       var cc = messages.getCc().replace(/^.+<([^>]+)>$/, "$1");
       var ccLower = cc.toLowerCase;

       //srAry.push(sndr);
       //srAry.push(rcpnt);
       //srAry.push(cc);



    var isIn = joinAddr.search(sndr || rcpnt);

     if(isIn == -1){

      var instance = k;
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
Clayten
  • 53
  • 1
  • 9
  • missing some code? try to remove as much clutter as possible while still reproducing the issue – le_m Mar 24 '17 at 00:20
  • Your variables are probably `String`s. Try to do something like `var instance = parseInt(k) + parseInt(startingEmail)` to perform a mathematical addition operation instead of concatenation. – Titus Mar 24 '17 at 00:28

1 Answers1

0

I can't see the example in your code but it sounds like you can just wrap Number() around your variable and it will perform the type conversion so the code will perform the math instead of concatenating as strings.

Cooper
  • 59,616
  • 6
  • 23
  • 54