In a JavaScript application that I am working on I have an array of objects:
function Message(title, message) {
this.title=title;
this.message=message;
}
var MessageArray = new Array();
MessageArray[0] = new Message("Some Title", "Some new message.");
I have an issue that I need to debug. Is there any way to read or sniff the current objects in the array, including their title and message properties? I could add another function to alert() me with those values, but if there is a tool that I could use much like the Visual Studio debugger then I would love to know about it. I took a look at Firebug but it does not seem to have this capacity.
To be clear, I am looking for a debugger that will let me inspect any variable at runtime, not specifically MessageArray at the moment. I did find Chrome’s Scope Variables pane, but it seems to only list scalars, not arrays!
Most modern browsers have a built in developers console with all the functionality of a normal debugger. Breakpoints and variable inspecting ect. In chrome you can open it through the tools menu or by pressing f12.
You can also use the JavaScript
Console.log();to log anything you want to the developer console. This stop you using alerts which stop JavaScript executing while the alert it up.In the case
console.log(MessageArray[0].title, MessageArray[0].message);would print out the title and the message to the console.EDIT:
Here is a screen shot of the console inside chrome. Showing me create your objects and then interacting with them via the console.