Last active
February 24, 2025 09:27
-
-
Save bhaireshm/d9a4ff4dc371cea6f391ff35100e10f1 to your computer and use it in GitHub Desktop.
Print the object's key values in aligned way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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]}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.