Search code examples
google-apps-scriptgoogle-sheets

Google Script If statement matching 0 as blank


I have a google sheet with some scripting in it.

Part of the scripting is it loops through an array that has been populated and carries out some functions if it comes across blank is a specific field.

My code is all working perfectly, except for this one anomoly where my if statement is activating when the value of the array field is 0 instead of ''

for (x = i; x<fullDataArray.length; x++) {

    if (fullDataArray[x][8] == '') {
      Logger.log(fullDataArray[x][8])
      break;
    }

This is the segment of my code that is causing issues. I put the Logger.log in there to display the value of the field that is causing the if statement to activate and then break out of my for loop. Put the screenshot of this below (Haven't included all the code as not necessary and would make this question really long)

enter image description here

Do I need to include a check for 0 in my if statement? I don't understand why it goes into the if statement section when the value isn't blank it's a 0.


Solution

  • Try:

    for (x = i; x<fullDataArray.length; x++) {
    
    if (fullDataArray[x][8] === '') {
      Logger.log(fullDataArray[x][8])
      break;
    }