Last active
June 6, 2022 09:40
-
-
Save awps/febd6e2ac791ab4cbface23e7f13b4d6 to your computer and use it in GitHub Desktop.
Convert any value to array. Typescript
This file contains 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
export const anyToArray = (value: any) => { | |
if (!value){ | |
return []; | |
} | |
if (Array.isArray(value)){ | |
return [...value]; | |
} | |
if (typeof value === 'object'){ | |
return Object.values(value); | |
} | |
return [value]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment