I have this JavaScript code:
console.log(obj);// [query: "wordOfTheDay"] console.log(note + " : " + obj ); // obj does not show up
I want to make "obj" display in the same string as "note" no matter the type it come in as.
For example:
console.log("text sample : " + obj ); // text sample : [query: "wordOfTheDay"]
Thank you!
Method 1 — Use console.log() method called with an object or objects as arguments will display the object or objects.
Stringify a JavaScript ObjectUse the JavaScript function JSON.stringify() to convert it into a string. const myJSON = JSON.stringify(obj); The result will be a string following the JSON notation.
We can use the console. log() method to display JavaScript values. To do that, we need to activate debugging in our browser with F12, and select "Console" in the debugger menu.
console.log
accepts any number of parameters, so just send each piece as its own param. That way you keep the formatting of the object in the console, and its all on one entry.
var obj = { query: 'wordOfTheDay', title: 'Frog', url: '/img/picture.jpg' }; console.log( "Text Here", obj); // Text Here Object {query: "wordOfTheDay", title: "Frog", url: "/img/picture.jpg"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With