'how to retrieve the value of a key in session storage

How to retrieve the value of a key in session storage? I want to test the value of a key in session storage in a condition but it returns a negative result yet the value "student " is the value of the "roles" key, here is a schema on the code.

this.$q.sessionStorage.set('current_user', infos)
this.$q.sessionStorage.set('fullname', fullname)
this.$q.sessionStorage.set('roles', roles)

const professorRole = sessionStorage.getItem("roles")
const studentRole = sessionStorage.getItem("roles")

//console.log("stu " + professorRole);

if (studentRole !== null && studentRole.indexOf(2) === "student") {
    
    console.log('email exists');
} else  {
    console.log('email not ok');
}


Solution 1:[1]

You could use either of the methods

getKey (index) => String,null or getAllKeys () => Array

on this.$q.sessionStorage

to retrieve the value of a key in session storage

Example:

let keys = this.$q.sessionStorage.getAllKeys()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alpesh Patil