Search code examples
javascriptgoogle-apps-scriptvariable-length

Why can't I get an array length after I split a string in google script?


In Google script, after I split a string, I can't then get the length of the resulting array. I guess it's not an array? If so, how can I turn it into an array with a length value?

function splitAndCount() {
  str = "33,34,35"; //example string
  var stringSplit = str.split(","); //split string
  return stringSplit.length(); //
  // TypeError: Cannot call property length in object 33,34,35. It is not a function, it is "number". 
}

Solution

  • It's not a function, it's property

    function splitAndCount() {
      str = "33,34,35"; //example string
      var stringSplit = str.split(","); //split string
      return stringSplit.length
    }
    
    console.log(splitAndCount())