Guest User

Untitled

a guest
Mar 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. function isObject(obj) {
  2. return obj === Object(obj);
  3. }
  4.  
  5. function formatData(obj, indents) {
  6. const objEntries = Object.entries(obj);
  7. for (var i = 0; i < objEntries.length; i++) {
  8. const key = objEntries[i][objEntries[i].length - 2];
  9. const value = objEntries[i][objEntries[i].length - 1];
  10.  
  11. if (!isObject(value)) {
  12. console.log("\t".repeat(indents) + key + ": " + value)
  13. if (i === objEntries.length - 1) {
  14. console.log("-".repeat(50));
  15. }
  16. } else {
  17. console.log("\t".repeat(indents) + key + ":");
  18. formatData(value, (indents + 1));
  19. }
  20. }
  21. }
  22.  
  23.  
  24. function printDetails(obj) {
  25. formatData(obj, 0);
  26. }
Add Comment
Please, Sign In to add comment