How can I convert a JavaScript object into a string?
Example:
var o = {a:1, b:2} console.log(o) console.log(\'Item: \' + o)
Output:
1.
JSON.stringify(o);
Item: {"a":"1", "b":"2"}
2.
var o = {a:1, b:2}; var b=[]; Object.keys(o).forEach(function(k){b.push(k+":"+o[k]);}); b="{"+b.join(', ')+"}"; console.log('Item: ' + b);
Item: {a:1, b:2}