Languages
[Edit]
EN

JavaScript - convert base64 to string

0 points
Created by:
Adnaan-Robin
274

In this article, we would like to show you how to convert Base64 to string in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

const encoded = 'c29tZSB0ZXh0Li4u';

const decoded = atob(encoded);
console.log('Converted text: ' + decoded);  // some text...

 

1. Encode

In this example, we use btoa() method to create a Base64-encoded ASCII string.

// ONLINE-RUNNER:browser;

const encoded = 'c29tZSB0ZXh0Li4u';

// convert base64 to string
const decoded = atob(encoded);

console.log('Base64 text:  ' + encoded);  // c29tZSB0ZXh0Li4u
console.log('Decoded text: ' + decoded);  // some text...

Output:

Base64 text:  c29tZSB0ZXh0Li4u
Decoded text: some text...

Related posts

References

  1. btoa() - Web APIs | MDN
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join