let entityTree = {
account: ['account_subscriptions', 'device'],
device: 'device_subscriptions'
}
function xxx(key) {
let val = entityTree[key];
const nextKey = Array.isArray(val) && (val = [...val], val.pop());
return val ? [].concat(key, val, xxx(nextKey)) : [];
}