Javascript Gotchas

By | February 16, 2024

In most of the scenario we are looking for jquery plugin or 3rd party library for even simple stuffs that can easily be done using javascript. In this post, I will list down the simple javascript ways to do the stuffs so that we don’t need to overload our applications with so many plugins.

JSON to Pretty Print JSON string

var emp = { name:'John Doe', 'email':'foo@bar.com', age: 40, address:{ line1: '1st  street', city:'New York', 'country': 'India'}};
var str = JSON.stringify(obj, undefined, 4); // indentation level = 4