Just wanted to verify some thought regarding split function. I have constructed a simple code.
var array1 = [{}];
var string1 = "A, B, C, D";
array1 = string1.split(",");
The problem is based on this kind of coding for example in flash. The string1 will split all ","
then transfers it to the array1 in this format ["A","B","C", "D"]
. Is this kind of concept similar to Google Spreadsheet - GAS? If yes can you site some example? Thanks a lot guys.
P.S: When I tried splitting the ","
it only returns the value "A B C D"
as a single element.
Thanks, Nash :)
Your code should definitely work, I just ran this with a breakpoint on Logger.log(array1);
The debugger shows it as an array, and the log logs it as: [A, B, C, D]
. Note, that to get the output you wanted I had to add a space to the split to get: string1.split(", ");
function myFunction() {
var array1 = splitTest();
Logger.log(array1);
}
function splitTest() {
var array1 = [{}];
var string1 = "A, B, C, D";
array1 = string1.split(", ");
return array1
}
J.Doe, I cannot submit a comment either, but your problem here is that if you get the value from a form, its type can be an object instead of a string. Hence you are getting the error of no function in object.
You can go around this by converting those objects to strings this way:
objectPretendingString = JSON.stringify(objectPretendingString) //becomes a string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With