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

138
Views
restar las mismas variables en un solo objeto javascript

 const token = [ {"token":"d2r4Z62OTGiPyNmdHTUfny", "time":1652767811}, {"token":"dnl13twkQIqifdvaxp1t6e", "time":1652767811}, {"token":"eDZxQu0FSWm72D2-T1md5X", "time":1652767811}, {"token":"dnl13twkQIqifdvaxp1t6e", "time":1652767811}]; // Try edit me const arr = []; for (var i=0; i<=token.length-1; i++) { const millis = Date.now(); const time = Math.floor(millis / 1000); if (token[i].time > time) { arr.push(token[i].token) } } console.log(arr);

entre estas dos variables de token son iguales, quiero distinguirlas entre sí, ¿cómo puedo hacer eso? Salida de ejemplo:

 const example = [ "d2r4Z62OTGiPyNmdHTUfny", "eDZxQu0FSWm72D2-T1md5X", "dnl13twkQIqifdvaxp1t6e" ]; console.log(example);

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

0

La forma más fácil con su lógica actual es que puede usar includes para verificar el token con los resultados de arr . Si está en arr , no necesitamos empujarlo a arr .

 const token = [ {"token":"d2r4Z62OTGiPyNmdHTUfny", "time":1652767811}, {"token":"dnl13twkQIqifdvaxp1t6e", "time":1652767811}, {"token":"eDZxQu0FSWm72D2-T1md5X", "time":1652767811}, {"token":"dnl13twkQIqifdvaxp1t6e", "time":1652767811}]; const arr = []; for (var i=0; i<=token.length-1; i++) { const millis = Date.now(); const time = Math.floor(millis / 1000); if (!arr.includes(token[i].token) && token[i].time > time) { arr.push(token[i].token) } } console.log(arr);

about 4 years ago · Juan Pablo Isaza Report

0

Simplemente use un Set ya que no permite duplicados:

 const tokens = [ {"token":"d2r4Z62OTGiPyNmdHTUfny", "time":1652767811}, {"token":"dnl13twkQIqifdvaxp1t6e", "time":1652767811}, {"token":"eDZxQu0FSWm72D2-T1md5X", "time":1652767811}, {"token":"dnl13twkQIqifdvaxp1t6e", "time":1652767811} ]; const now = Math.floor(Date.now() / 1000); const result = new Set( tokens.filter(({ time }) => time > now).map(({ token }) => token) ); console.log(...result);

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!