Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Using console.log() to display Object as string returns [object Object]

I tried to pull some data from a json file and so I used console.log() to test it. To make sure it's easier to read, I used template literals to highlight it with some extra information. However, I keep getting [object, Object]. I assumed that I failed to pull the data and inspected the json file data for hours. Eventually, I found out I require the data correctly but it was console.log() failed me.

So I thought it's a template literals thing, so I tried the other two ways and they still got the same results. Why?

var obj = {
    "date": "Sun Jun 14 21:36:17 UTC 2009",
    "user": "captain_pete",
    "tweet": "Reading the tweets coming out of Iran... The whole thing is terrifying and incredibly sad..."
}

console.log(obj)
console.log('Obj1: ' + obj)
console.log('Obj2: ' + obj.toString()
console.log(`Obj3: ${obj}`)

Output:

{date: 'Sun Jun 14 21:36:17 UTC 2009', user: 'captain_pete', tweet:'Reading the tweets coming out of Iran... The whole thing is terrifying and incredibly sad...'} 
Obj1: [object Object]
Obj2: [object Object] 
Obj3: [object Object]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The last three lines are all invoking Object.toString() on obj, which by default returns a string in the form of [object type].

If you want the object as a string, you can use JSON.stringify:

var obj = {
    "date": "Sun Jun 14 21:36:17 UTC 2009",
    "user": "captain_pete",
    "tweet": "Reading the tweets coming out of Iran... The whole thing is terrifying and incredibly sad..."
}

Object.prototype.toString = function(){
  return JSON.stringify(this)
}

console.log(obj)
console.log('Obj1: ' + obj)
console.log('Obj2: ' + obj.toString())
console.log(`Obj3: ${obj}`)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!