M
M
migoz2020-04-27 21:22:39
JavaScript
migoz, 2020-04-27 21:22:39

Key generation in LocalStorage?

Whether it is possible to make the following: there is a form - login and password. I want to save the logs and password in localStorage for the test. How to make it so that after submitting the form by different users, such an entry in the storage occurs, for example:

user1:  'login: azimut, password: 123',
 user2:  'login: bro, password: 234'


That is, so that the key is automatically increased (user1 ...... user12) after the form is submitted and thus there is no overwriting. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-04-27
@loonny

let keyName = 'user' + localStorage.length;
localStorage.setItem(keyName, 'login: azimut, password: 123');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question