Skip to content
loading...

Logging like a PRO in javascript

ziishaned profile image Zeeshan Ahmd twitter logo github logo Updated on ・1 min read  

Inside JavaScript there is a built-in function JSON.stringify which converts any variable into json string.

The syntax is:

JSON.stringify(value, replacer, space)
  1. value - Any variable you want to convert into JSON string
  2. replacer - This method will be called on each item of the variable
  3. space - Number of spaces you want to add to each item of the variable

The second and thrird arguments are optional.

Lets have a look at the following example:

const users = [
  {
    name: 'John',
    isActive: false,
  },
  {
    name: 'Jane',
    isActive: true,
  },
];
console.log(JSON.stringify(users, null, 2));

Upon running above code you will get the following output:

Output

twitter logo DISCUSS (1)
Discussion
markdown guide
Classic DEV Post from Jul 26 '19

🎩 JavaScript Enhanced Scss mixins! 🎩 concepts explained

In the next post we are going to explore CSS @apply to supercharge what we talk about here....

Zeeshan Ahmd profile image
Full-stack web developer and open source lover