score:0

Accepted answer
const input = { a: { b: 22, c: "hello", d: { f: 10 } }, e: 456 };
function flat(data, key = "", result = []) {
  for (let k in data) {
    if (typeof data[k] === "object") {
      flat(data[k], key + k + ".", result);
    } else result.push({ [key + k]: data[k] });
  }
  return result;
}
console.log(flat(input));

score:1

const input = {
  a: {
    b: true,
    c: 'hi',
  },
  d: 123
}

function convert(data, prev = '') {
  return Object.entries(data).reduce((r, [k, v]) => {
    let key = prev + (prev ? '.' : '') + k;

    if (typeof v == 'object') {
      r.push(...convert(v, key))
    } else {
      r.push({ [key]: v })
    }

    return r;
  }, [])
}

const result = convert(input)
console.log(result)

Related Query

More Query from same tag