Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
Creating a random number for a local storage keyName

I am trying to create a random number as the keyName for a local storage for example in this code: localStorage.setItem('_8bcsk999r778311o', input.value); I want to create a random number in the place of "_8bcsk999r778311o" using javascript . Is it possible , and if possible , could you please send me the code? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Takes a number from 1 to 10 and save into number then with floor convert number to integer

//random integer from 0 to 10000:
let number = Math.floor(Math.random() * 10000);
localStorage.setItem(number, input.value);

In JavaScript, floor() is a function that is used to return the largest integer value that is less than or equal to a number. see more

Math.random() returns a random number between 0 (inclusive), and 1 (exclusive): see more

about 4 years ago · Juan Pablo Isaza Denunciar

0

const random_id = `_${Math.random().toString(30).substr(2,17) + Math.random().toString(30).substring(2,17)}`
console.log(random_id)

//localStorage.setItem(random_id, 'value goes here');

Very simple and fast solution

about 4 years ago · Juan Pablo Isaza Denunciar

0

var key = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for (var i = 0; i < Math.floor(10+10*Math.random()); i++) {
    key += possible.charAt(Math.floor(Math.random() * possible.length));
}
localStorage.setItem(key, input.value);

I hope this will be helpful for you. Thanks.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda