JSFiddle - React, Tailwind, and code Playground

by Aniket Suryavanshi

JavaScript

const abc = {
  a: '123',
  b: [{ c: 1, d: true }],
  e: {
    f: {
      g: { h: NaN }
    }
  }
};
// output: a, b, c. d, e, f, g, h

function printKeys (obj) {
  Object.keys(obj).forEach(key => {
  console.log(key);
  	if(typeof obj[key] === "object") {
    	if(Array.isArray(obj[key])) {
      	obj[key].forEach(elem => {
        	if(typeof elem === "object") {
          	printKeys(elem);
          }
        })
      } else {
      	printKeys(obj[key]);
      }
    }
	  
  });
}

printKeys(abc);