A JavaScript object may appear as [object Object] when it is combined with a string, hiding the properties you wanted to inspect. To print an object in JavaScript, pass it directly to the console or serialize the data to readable JSON when a text snapshot is appropriate.
Print Object JavaScript: Inspect in the Console
Open the developer console in a browser such as Chrome and run:
const order = {
id: 17,
customer: { name: "Ada", city: "Boston" },
items: ["book", "pen"]
};
console.log(order);
console.log(order.customer.name); // Ada
The first call displays an expandable object in Chrome DevTools. Expand customer to inspect name and city, and expand items to see the array entries. The second call prints the string Ada directly. Exact formatting varies by console and version; the underlying property access is standard JavaScript.
For a JavaScript print object workflow, passing the object as a separate argument preserves the console’s interactive view: console.log("order:", order). By contrast, console.log("order: " + order) converts this ordinary object to a string, typically producing order: [object Object]. That string is not a listing of its fields.
Understand Changes After Logging
A console can display an object by reference and evaluate properties when you expand it. If the object changes after logging, the expanded view may reflect the later state. The behavior and preview details depend on the environment, so do not use an expandable entry as proof of the object’s exact earlier state.
const state = { count: 1 };
console.log(state);
state.count = 2;
console.log(state.count); // 2
To capture a specific value at log time, log a primitive such as state.count. If you need a textual snapshot of suitable data, serialize it before the mutation. A shallow copy such as { ...state } copies top-level properties but still shares nested object references; it is not a complete snapshot of a nested structure.
Make a Readable Text Snapshot
JavaScript dump object: for JSON-compatible data, use JSON.stringify() with indentation:
const snapshot = JSON.stringify(order, null, 2);
console.log(snapshot);
The output is a string containing:
{
"id": 17,
"customer": {
"name": "Ada",
"city": "Boston"
},
"items": [
"book",
"pen"
]
}
The third argument sets two spaces of indentation. Because the string is created immediately, later changes to order do not alter snapshot. This way of printing an object with JavaScript is convenient for a log or a small reproducible example, but serialization has limits.
JSON omits object properties whose values are functions, symbols, or undefined; such array entries become null. A circular reference causes JSON.stringify() to throw, and a BigInt value also throws by default. Special objects can serialize differently from their interactive console view, including through a toJSON() method. See the MDN reference for JSON.stringify before treating the output as a complete copy.
Choose Output for the Investigation
To print an object in the JavaScript console during debugging, use direct logging when you need to expand properties interactively. Use a formatted JSON string when the data is compatible and you need readable text fixed at serialization time. For a single field, logging that value directly is often clearer than scanning a large object.
For example, the print object JavaScript operation console.log(order.customer.city) outputs Boston. Check that each intermediate property exists before accessing it when input can be incomplete. In a table of records, consider console.table() for a compact view, but inspect nested structures separately when the table hides useful detail.
Review what the object contains before logging it. Credentials, tokens, personal data, and other sensitive values can persist in browser logs or shared reports. Log only the fields needed to diagnose the problem, and remove temporary diagnostic output when it is no longer useful.
