我有一个自定义日志记录功能,可以登录到这样的firebug控制台:
// the name here is just for fun
function ninjaConsoleLog() {
var slicer = Array.prototype.slice;
var args = slicer.call(arguments);
console.log(args);
}
它的工作方式与我想要的完全相同....除非我在数组中的字符串值大于7个字,否则firebug控制台会隐藏字符串值,除了前两个单词和后两个单词。 (大约)
示例:
ninjaConsoleLog("This is a longish string, like the energizer bunny, it just keeps going and going and going.");
上述函数调用导致以下输出到firebug控制台:
["This is a longish strin...going and going."]
这很好,除了有时控制台缩写的字符串部分包含重要数据。
首先,为什么会发生这种情况?
其次,使用我当前的日志记录功能,无论如何我是否可以强制控制台输出数组中每个项目的完整字符串值?或者只是在查看控制台的输出时查看整个字符串?
或者这不可能吗?
谢谢!
答案 0 :(得分:8)
尝试将其更改为console.dir(args)而不是console.log(args)
此外,您应该能够单击firebug控制台中的值以将其扩展为完整值 盒子符号中将有一个加号,或者当您将鼠标悬停在该值上时,它将加下划线,这意味着单击它将扩展为其完整值
答案 1 :(得分:1)
如果要查看整个字符串而不必展开单个数组项(dir()将列出折叠结果),可以在数组上调用toString()
,Firebug将向您显示整个字符串数组作为字符串,例如:
var arr = [
"This is a longish string, like the energizer bunny, it just keeps going and going and going.",
"Another longish string Another longish string Another longish string Another longish string.",
"A third longish string A third longish string A third longish string A third longish string."
];
console.log(arr.toString());
...导致此字符串:
This is a longish string, like the energizer bunny, it just keeps going and going and going.,Another longish string Another longish string Another longish string Another longish string.,A third longish string A third longish string A third longish string A third longish string.