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

188
Vistas
How to define a variable with another variable value

I have a list of variables with dates as variable names like a290322, a300322, a310322 etc..

var a270322 = "https://google.com" ;
var a280322 = "https://youtube.com" ;
var a290322 = "https://facebook.com" ;
var a300322 = "https://twitter.com" ;
var a310322 = "https://instagram.com" ;
var a010422 = "https://sgquizdaily.com" ;
var a020422 = "https://maps.google.com" ;
var a030422 = "https://gmail.com" ;
var a040422 = "https://docs.google.com" ;

Now I want to declare a new variable named Today

The value of Today variable should match to the variable from the list of variables.

Manually day by day I can modify line like below.

var today = a300322 ;

But I don't know how to get it by script.

Can you help in assigning today dated variable value to Today?

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

0

you can store the variable into an object so you can store and call the value based on the key like this

var a270322 = "https://google.com" ;
var a280322 = "https://youtube.com" ;
var a290322 = "https://facebook.com" ;
var a300322 = "https://twitter.com" ;
var a310322 = "https://instagram.com" ;
var a010422 = "https://sgquizdaily.com" ;
var a020422 = "https://maps.google.com" ;
var a030422 = "https://gmail.com" ;
var a040422 = "https://docs.google.com" ;

const variables = {
  a270322,
  a280322,
  a290322,
  a300322,
  a310322,
  a010422,
  a020422,
  a030422,
  a040422,
};

var today = 'a300322';

console.log(variables[today]); // https://twitter.com
about 4 years ago · Juan Pablo Isaza Denunciar

0

Get the current date through Date(), padding to 2 digits, slicing last two, prepend with 'a' and eval.

var a270322 = "https://google.com" ;
var a280322 = "https://youtube.com" ;
var a290322 = "https://facebook.com" ;
var a300322 = "https://twitter.com" ;
var a310322 = "https://instagram.com" ;
var a010422 = "https://sgquizdaily.com" ;
var a020422 = "https://maps.google.com" ;
var a030422 = "https://gmail.com" ;

const now = new Date()
var day = ('0' + now.getDate()).slice(-2)
var month = ('0' +(now.getMonth() + 1).toString()).slice(-2)
var year = (now.getFullYear().toString()).slice(-2)
var Today = 'a'+ day + month + year
console.log(Today)

TodaysUrl = eval(Today)
console.log(TodaysUrl)

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