尝试了各种各样的事情
split[6].length
String.split[6].length
沿着这些行没有成功获取最后一个错误消息...
ReferenceError:未定义“string”。
嗨感谢所有的回复,最后我根据原始数组的索引创建了一个数组,然后查询了它的长度。如您所见,我无法从输入字符串中删除单引号和双引号。新的javascript和它让我有点疯狂哈哈。
// Loop through all the input messages
for (var i = 0; i < input.length; i++) {
var next = output.append(input[i]);
// Get the body of the current input message
var body = input[i].text;
// Set the body
next.text = body ;
next.text.replace(/\'/g, "'");
next.text.replace(/\"/g, """);
//replace(/['"]/g,'');
// Set a property
var split = next.text.split(",");
var array1 = split[5];
var array2 = split[2];
next.setProperty("aaaLength", split.length);
next.setProperty("aaaSplitValue", split.length);
next.setProperty("aaaArray1Value", split.length);
next.setProperty("aaaArray2Value", split.length);
if (next.getProperty("BaseFilename")=="name"){
next.text.replace(/\'/g, "'");
next.text.replace(/\"/g, """);
//replace(/['"]/g,'');
if(split.length>10){
next.setProperty("FullFilename","nameError"+i);
next.setProperty("BaseFilename","nameError"+i);
next.setProperty("Suffix",".err");
}
if(array1.length>10){
next.setProperty("FullFilename","nameSnameSuffixError"+i);
next.setProperty("BaseFilename","nameSnameSuffixError"+i);
next.setProperty("Suffix",".err");
}
}
答案 0 :(得分:3)
如果元素是字符串,则长度应该有效。请参阅http://jsfiddle.net/46nJw/
中的以下操作var parts = "foo,bar,baz,foop".split(/,/);
alert( parts[3].length ); // should alert 4
答案 1 :(得分:0)
var arr = ['one','two','three']
arr[1].length
返回3
答案 2 :(得分:0)
你确定它正在返回一个字符串吗?
您可以强制它转换为如此字符串:
String(split[6]).length;
答案 3 :(得分:0)
我不知道你需要什么,所以我给你所有我能想到的选择:
var commaSeparatedString = "one, two, three";
var str = commaSeparatedString.split(",");
alert (str.length) // outputs '3'
alert (str[2]); // outputs 'three'
alert (str[2].length); //outputs '5'