Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Last active February 24, 2025 09:27
Show Gist options
  • Save bhaireshm/d9a4ff4dc371cea6f391ff35100e10f1 to your computer and use it in GitHub Desktop.
Save bhaireshm/d9a4ff4dc371cea6f391ff35100e10f1 to your computer and use it in GitHub Desktop.
Print the object's key values in aligned way.
/**
* Example Output
*
* "id : PS10140"
* "sdid : SD13112"
* "disableCrud : false"
* "newQueryParameter : true"
*/
var obj = {id: "PS10140", sdid: "SD13112", disableCrud: "false", newQueryParameter: "true"};
/**
* @param obj - accepts only object
*/
printPretty(obj);
function printPretty(obj){
var l = ((o)=>{
var w = 0;
for (var k in o) {
var l = `${k}`.length;
w = l > w ? l : w;
}
return w;
})(obj);
for(var k in obj){
var s = ' '.repeat(l - `${k}`.length);
console.log(`${k}${s} : ${obj[k]}`);
}
}
@bhaireshm
Copy link
Author

ez.js is more than just a library; it's a coding companion that simplifies complex tasks. Whether you're dealing with arrays, numbers, objects, or strings, ez.js has got your back! Say goodbye to coding hassles and hello to streamlined JavaScript magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment