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:
It appears JSON accept the second parameter that could help with functions - replacer, this solves the issue of converting in the most elegant way:
JSON.stringify(object, (key, val) => { if (typeof val === 'function') { return String(val); } return val; });