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

152
Views
How to set expiration of an element inside array in javascript / nodejs?

Is it possible to set an expiration of an element inside the array? For example, I added element "A" inside an array and after n Hours it is automatically removed from the array.

If it is possible, then can you please provide me an example?

I'm newbie to javascript and node js so please don't go way too complicated. and also please don't mind if I have added silly question.

Thanks in advance!

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

0

You can simulate an expiration by using setTimeout to execute a callback function which deletes the item in the array after a certain delay:

const array = [1, 2, 3]

console.log('Before: ', array)

function setExpiration(array, itemIndex, delay){
  setTimeout(() => array.splice(itemIndex, 1), delay)
}

setExpiration(array, 1, 2000)

setTimeout(() => console.log('After: ', array), 2001)

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!