getLocalStorageItem

this.getLocalStorageItem Function

Description

With this method, a value previously stored in the browser’s localStorage can be retrieved. The function also checks whether the stored item has expired (based on its TTL) and automatically removes it if expired.

If the item is still valid, its expiration time is renewed, keeping it active for the same TTL duration again.


Parameters

Name
Type
Description

key

String

The key under which the item is stored in localStorage.


Returns

Type
Description

Any / null

Returns the value if the item exists and is not expired, otherwise returns null.


Usage Example

var value = this.getLocalStorageItem("my_test_key");

Retrieves the value previously stored under the key "my_test_key". If the item exists and is still valid (not expired), the value is returned. Otherwise, null is returned.


Important Notes

  • If the item is not found or has expired, the function returns null.

  • If the TTL or expiry is missing (e.g., due to older format), the function will apply the current system default TTL.

  • When a valid item is returned, its expiration is updated, extending its validity.

  • The function checks if localStorage is available using jentis.helper.bIsLocalStorageAvailable.

  • Do not use this function inside nested functions where the this context might be lost.

Last updated

Was this helpful?