0

I'm trying to print out both user and company objects when i use console.log(user,company) it all working fine and i can see the objects content but the outformat is not desired . i tried to template it with backticks but in that case i just get an output like [object, object] is there a way to both format and see inside object at the same time ? User and Company are two classes that made objects with same names respectively and the code below is what im trying to achieve .

import { User } from "./User";
import { Company } from "./Company";
const user = new User();
const company = new Company();
console.log(`
${user}
${comapny}
`);
ItsJay
  • 188
  • 4
  • 17
  • 1
    Does this answer your question? [How can I display a JavaScript object?](https://stackoverflow.com/questions/957537/how-can-i-display-a-javascript-object) – palaѕн May 06 '20 at 06:30
  • @palaѕн not pretty much ... i mean the question was asked like 10years ago .. es6 has not been introduced yet and its using object directly without backtick ... i was seeking for a solution via backtick to get off that manual formatings – ItsJay May 06 '20 at 06:58

2 Answers2

0

You should give a try to:

JSON.stringify(user, null, 2)
JSON.stringify(company, null, 2)
Simon Bruneaud
  • 2,263
  • 2
  • 12
  • 24
0

Implement method toString() in your User and Company classes.

Riad Baghbanli
  • 3,105
  • 1
  • 12
  • 20