Skip to content

Instantly share code, notes, and snippets.

@nikita-rudenko
Last active November 3, 2021 00:53
Show Gist options
  • Select an option

  • Save nikita-rudenko/3c6b3ef34e93faa9b657f6ecb1f884fa to your computer and use it in GitHub Desktop.

Select an option

Save nikita-rudenko/3c6b3ef34e93faa9b657f6ecb1f884fa to your computer and use it in GitHub Desktop.
/**
* Gets all values from object regardless of their level of nesting
*/
export const getAllObjectValues = <T>(obj: { [key: string]: any }): T[] => {
const values = [];
for (let i = 0; i < Object.values(obj).length; i += 1) {
const element = Object.values(obj)[i];
if (typeof element === "object" && element !== null) {
values.push(...getAllObjectValues(element));
} else {
values.push(element);
}
}
return values;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment