Skip to content

Instantly share code, notes, and snippets.

@awps
Last active June 6, 2022 09:40
Show Gist options
  • Save awps/febd6e2ac791ab4cbface23e7f13b4d6 to your computer and use it in GitHub Desktop.
Save awps/febd6e2ac791ab4cbface23e7f13b4d6 to your computer and use it in GitHub Desktop.
Convert any value to array. Typescript
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