Code Monkey home page Code Monkey logo

Comments (7)

climba03003 avatar climba03003 commented on August 13, 2024 2

but I haven't found any doc to describe it.

console.log said it using util.format.
image

util.format said it using util.inspect for object.
image

util.inspect is telling you depth is 2 by default.
image

from help.

kylo5aby avatar kylo5aby commented on August 13, 2024 1

I'm happy to fix it

from help.

climba03003 avatar climba03003 commented on August 13, 2024 1

I'm happy to fix it

Shouldn't it just display issue?
Since REPL or console.log do not like browser provide a way to expend each property, the display of [Object] still means it is a proper object.

https://nodejs.org/api/util.html#utilinspectobject-showhidden-depth-colors
The maximum depth of console.log show is 2.

import pug from 'pug'

const html = pug.render('p= data', {
  data: {
    string: 'example text',
    object: { string: 'text 2', object: { string: 3 } } // not [Object]
  }
})

console.log(html) // <p>[object Object]</p>

pug is actually printing the object using .toString and that is expected result.

from help.

aduh95 avatar aduh95 commented on August 13, 2024 1

It has nothing to do with JSON.parse(), as @climba03003 mentioned it's the documented behavior of console.log(). You should first convert the data to a string with e.g. JSON.stringify(), util.format(), or a third party library.

from help.

kylo5aby avatar kylo5aby commented on August 13, 2024

Sounds reasonable, the default depthofconsole.logis 2, that's why{ string: 3 }` doesn't been shown, but I haven't found any doc to describe it.

from help.

aliakbar192 avatar aliakbar192 commented on August 13, 2024

In your code, you're correctly stringifying an object and then parsing it back into an object. However, when you pass _data to your Pug template, you're assigning the entire object to a variable called data. This is why you're seeing [object Object] in your view because data is an object, and Pug is displaying it as a string representation.

from help.

RedYetiDev avatar RedYetiDev commented on August 13, 2024

(This issue seems resolved)

from help.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.