© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
shahaparan
For example, var obj = {foo:"bar"} . I need to convert as token like this "aasasdfasdf" . After creating token, I need to save the browser . How can I implement this ?
Marco Alka
Software Engineer, Technical Consultant & Mentor
Do you mean that you want to
?
You can do it like this:
const obj = { foo: 'bar' }; // 1. serialize it const serializedObj = JSON.stringify(obj); // 2. store it localStorage.setItem('obj', serializedObj);
No need to "tokenize" (you probably mean base64-encode) it, though if you really want to do that, just do:
const base64Obj = btoa(serializedObj);
When inspecting the variables:
thanks
Marco Alka
Software Engineer, Technical Consultant & Mentor
Do you mean that you want to
?
You can do it like this:
const obj = { foo: 'bar' }; // 1. serialize it const serializedObj = JSON.stringify(obj); // 2. store it localStorage.setItem('obj', serializedObj);No need to "tokenize" (you probably mean base64-encode) it, though if you really want to do that, just do:
const base64Obj = btoa(serializedObj);When inspecting the variables: