Skip to content

开坑

飞行棋

递归清理对象中的空对象

js
function clearEmpties(o) {
  for (var k in o) {
    if (!o[k] || typeof o[k] !== 'object') {
      continue;
    }
    clearEmpties(o[k]);
    if (Object.keys(o[k]).length === 0) {
      delete o[k];
    }
  }
  return o;
}