javascript console log object code example

Example 1: print object javascript

str = JSON.stringify(obj);
str = JSON.stringify(obj, null, 4); // (Optional) beautiful indented output.
console.log(str); // Logs output to dev tools console.
alert(str); // Displays output using window.alert()

Example 2: console.log object object

const language = this.converstaionLanguage; // {"lang":"en"} <- this is JSON

console.log(language); // [object Object]
console.log(JSON.stringify(language) // {"lang":"en"}

Example 3: console.log javascript

console.log(10);
console.log('You can also log numbers')

Example 4: cosnsole.log without obj object

console.log(JSON.stringify(myObject, null, 4));

Example 5: how to use js console log

console.log('string');

Example 6: nested array of object shows as object in console log output js

const util = require('util')

console.log(util.inspect(myObject, {showHidden: false, depth: null}))

// alternative shortcut
console.log(util.inspect(myObject, false, null, true /* enable colors */))

Tags:

Java Example