Last active
November 3, 2021 00:53
-
-
Save nikita-rudenko/3c6b3ef34e93faa9b657f6ecb1f884fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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