I want to encode my array contents with base64 if possible in javascript (and then decode later).
Example:
var array = ["stack", "overflow"]
// base64.encode(array)
I want to encode my array contents with base64 if possible in javascript (and then decode later).
Example:
var array = ["stack", "overflow"]
// base64.encode(array)
In order to use the well-known function btoa
, you'll first have to convert your array to string, in such a way that you can reverse the operation. JSON would be the string format to go for.
So to encode do:
base64 = btoa(JSON.stringify(array))
To decode do:
JSON.parse(atob(base64))