Created
November 17, 2024 00:23
-
-
Save vitaliisili/1894449447fd45977a6c34d8913d9a8e to your computer and use it in GitHub Desktop.
Save javascript data in file
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
const saveDataAsFile = (data: any, filename: string) => { | |
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); | |
const url = URL.createObjectURL(blob); | |
const a = document.createElement('a'); | |
a.href = url; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
// Clean up | |
document.body.removeChild(a); | |
URL.revokeObjectURL(url); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment