Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Cómo definir una variable con otro valor de variable

Tengo una lista de variables con fechas como nombres de variables como 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" ;

Ahora quiero declarar una nueva variable llamada Hoy

El valor de la variable Hoy debe coincidir con la variable de la lista de variables.

Manualmente, día a día, puedo modificar la línea como se muestra a continuación.

 var today = a300322 ;

Pero no sé cómo obtenerlo por script.

¿Puede ayudar a asignar el valor de la variable con fecha de hoy a Hoy ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

puede almacenar la variable en un objeto para que pueda almacenar y llamar al valor en función de la clave como esta

 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 Report

0

Obtenga la fecha actual a través de Date(), rellene hasta 2 dígitos, divida los dos últimos, anteponga 'a' y 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!