Persist User Settings | AIUI | Rokid

localStorage stores strings only. Use JSON.stringify() before saving an object and provide a default when no saved value exists.

Persist User Settings

localStorage stores strings only. Use JSON.stringify() before saving an object and provide a default when no saved value exists.

Complete the Example

localStorage stores strings only. Use JSON.stringify() before saving an object and provide a default when no saved value exists.

const settings = {
  language: 'zh-CN',
  speechEnabled: true
};

localStorage.setItem('settings', JSON.stringify(settings));

const saved = localStorage.getItem('settings');
const restored = saved ? JSON.parse(saved) : {};
console.log(restored);

See localStorage for removing and clearing data.