Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js base64 decode

作者:_永恒灬莫言   发布日期:2026-06-19   浏览:63

// Base64 解码示例代码

// 使用 atob() 函数进行 Base64 解码
function base64Decode(input) {
    try {
        // atob() 函数用于解码使用 base64 编码的字符串
        return atob(input);
    } catch (e) {
        // 如果解码失败,返回错误信息
        return "解码失败: " + e.message;
    }
}

// 示例
const encodedString = "Sm9obiwgeW91IGNhbiByZWFkIHRoaXM=";
const decodedString = base64Decode(encodedString);
console.log(decodedString);  // 输出: John, you can read this

解释说明:

  • atob() 是浏览器内置的函数,用于将 Base64 编码的字符串解码为原始字符串。
  • try...catch 用于捕获解码过程中可能出现的错误(例如,输入的字符串不是有效的 Base64 编码)。
  • encodedString 是一个 Base64 编码的字符串,通过 base64Decode 函数解码后,会输出原始的字符串。

上一篇:js property

下一篇:js base64编码

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js fill方法

js 数组连接

js json数组

js 数组复制

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站