-1

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". 
}
  • 2
    `length` is not a method, but a number property. No parentheses. The error really says it all. It is a number, not a function. so `stringSplit.length`. – trincot Jan 03 '20 at 18:21

2 Answers2

3

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())
Dominik Matis
  • 2,086
  • 10
  • 15
0

Remove parenthesis from stringSplit.length, it's not function

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