Firebug console shortening strings in array logged?

落花浮王杯 提交于 2019-12-14 03:55:05

问题


I have a custom logging function to log to the firebug console that looks like this:

// the name here is just for fun
function ninjaConsoleLog() {
    var slicer = Array.prototype.slice;
    var args = slicer.call(arguments);
    console.log(args);
}

And it works exactly like I want it to....except that if I have string values longer than about 7 words in the array, the firebug console hides the string value except for the first two words and the last two words. (approx.)

Example:

ninjaConsoleLog("This is a longish string, like the energizer bunny, it just keeps going and going and going.");

The aforementioned function call results in the following output to the firebug console:

["This is a longish strin...going and going."]

This would be fine, except that sometimes the part of the string that the console abbreviates contains important data.

First off, why does this happen?

Second, with my current logging function, is there anyway that I can either force the console to output the full string value for each item in the array? Or just view the entire string when viewing the console's output?

Or is this not possible?

Thanks!!


回答1:


Try changing it to console.dir(args) instead of console.log(args)

Also you should be able to click on the values in firebug console to expand them to their full values There will be either a plus in a box symbol or when you mouse over the value it will become underlined, which means clicking on it will expand to its full value




回答2:


If you want view the entire string(s) without having to expand the individual array items (dir() will list collapsed results), you can call toString() on the array, and Firebug will show you the entire array as a string, e.g.:

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());

... which results in this string:

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.



来源:https://stackoverflow.com/questions/3359273/firebug-console-shortening-strings-in-array-logged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!