Last active
January 8, 2021 05:51
-
-
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