Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
998 views
in Technique[技术] by (71.8m points)

javascript - Google script string ends with ... and then undefined

I'm sure there's a very basic reason for my problem and I hope you'll point it out :) The problem I have is that a string shows up as ending with "..." on the line of creation but when continuing to the next line it turns into "undefined". Here's an example:

var string1 = "sdfsdfsdfsdfsdfsdfsfsfsfsdfsdfsdfsdfsdfsdfsfasdfasfasdflkjasldflasdkjflaksdjflasjdflaksjdflasdkjf";
var string2 = "sdfgsdfglksjdflgkjsdlfgkjlsdfgkjlsdkgjlkajsdlfkjladskjflakjdsflkajsdlfkjasdlfkjalsdkfjlaskdjflkasjdf";
var string3 = "sdfglksfdjlgkjsldfgkjlsdfkjglsdfkjglsdkfjglsdkjglsdkgjlsdfkjglsdkfjglsdkfjglsdkjglsdkfjglsdkfjglskfdjglsdkjfg";
var string = string1.concat(string2,string3); // debug breakpoint at this line shows the string as ending with ...
var length = string.length(); // debug breakpoint here shows "string" as undifiend but length apears to be working fine.

Any other functions I run on this string return an error as the string is undefined. Ideas?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The error is not that string is undefined. It's that string.length() is undefined.

Strings don't have a function length() in javascript. They have a property instead .length. The ellipsis you're seeing ... is probably just your console truncating the console output, but the entire string remains. See below.

var string1 = "sdfsdfsdfsdfsdfsdfsfsfsfsdfsdfsdfsdfsdfsdfsfasdfasfasdflkjasldflasdkjflaksdjflasjdflaksjdflasdkjf";
var string2 = "sdfgsdfglksjdflgkjsdlfgkjlsdfgkjlsdkgjlkajsdlfkjladskjflakjdsflkajsdlfkjasdlfkjalsdkfjlaskdjflkasjdf";
var string3 = "sdfglksfdjlgkjsldfgkjlsdfkjglsdfkjglsdkfjglsdkjglsdkgjlsdfkjglsdkfjglsdkfjglsdkjglsdkfjglsdkfjglskfdjglsdkjfg";
var string = string1.concat(string2,string3); // debug breakpoint at this line shows the string as ending with ...
var length = string.length; // debug breakpoint here shows "string" as undifiend but length apears to be working fine.
console.log(string);
console.log(length);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...