Skip to content

Convert a String to a Blob object in JavaScript

To convert a string to a blob in JavaScript we are going to pass the string to a Blob constructor and return the string.

Advertisements
const str2blob = txt => new Blob([txt]);

console.log(str2blob("Poopcode"))

//Blob {size: 8, type: ""}
//size: 8
//type: ""
//__proto__: Blob
See also  CSS code snippet - How to wrap text in div ?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.