The localForage is an open-source JavaScript library that refines the experience of saving data to web browser databases like localStorage, IndexedDB or WebSQL API.
It supports the majority of all types of browser databases.
It is absolutely asynchronous that simply uses browser databases and improves the universal offline experience of the web app.
In this tutorial, we’ll see how to save data to browsers in a much easier way with localforagesetItem() method.
Localforage setItem() method
With localforagesetItem(), developers are allowed to store multiple types of data not just strings.
It automatically manages and loads the best web browser driver(IndexedDB, WebSQL, and localStorage drivers).
It also supports to store blob and arbitrary type of data, so that we can store images, files, etc.
The localforage also allows developers to create multiple instances using createInstance() method, pointing to different stores.
varasianCountries=localforage.createInstance({countries:["India 🇮🇳","Singapore 🇸🇬","Israel 🇮🇱","Japan 🇯🇵"],});vareuropeanCountries=localforage.createInstance({countries:["Italy 🇮🇹","France 🇫🇷","Switzerland 🇨🇭","Sweden 🇸🇪"],});// Setting the key on one of these doesn't affect the other.
asianCountries.setItem("asianLanguages",["Hindi","English","Gujarati","Japanese","Hebrew",]);europeanCountries.setItem("europeanLanguages",["Italian","English","Romansh","Finnish",]);