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

410
Views
Javascript map object, skips element and sets a timeout

This is my object

[0 … 200]
0: {id: 2291798516830927, url: '.....', address: 'new', symbol: '1t43', fav: false}
1: {id: 7337710716729779, url: '.....', address: 'new', symbol: 'gf23525', fav: false}
2: {id: 6962996031953837, url: '.....', address: 'old', symbol: '435234', fav: false}
3: {id: 8456218226475281, url: '.....', address: 'old', symbol: '2345', fav: false}
4: {id: 6759748921116029, url: '.....', address: 'new', symbol: '$B2345ROKE', fav: false}
...


address="new"
bookmarks.map(function (bookmark, index) {
    setTimeout(() => {
        if (bookmark.address == address) {
           console.log(bookmark.symbol)
        }
    }, 1000 * index)
})

What I want to do is skip all the "old" addresses in my object and continue with the mapping. There should be a 2 second timeout if possible between each cycle.

if I use Timeout with value "1000 * index" after the first two objects I have to wait several minutes before the cycle resumes, it is not clear to me why.

if I use the timeout without with "1000" without "index" the timeout does not work, the object is printed entirely without timeout

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

0

I would filter and not use map. Never use a map when you mean forEach and do not need the array map is creating.

We can use setTimeout or setInterval and clear the inteval when cnt === list.length

const bookmarks = [ {id: 2291798516830927, url: '.....', address: 'new', symbol: '1t43', fav: false},
 {id: 7337710716729779, url: '.....', address: 'new', symbol: 'gf23525', fav: false},
 {id: 6962996031953837, url: '.....', address: 'old', symbol: '435234', fav: false},
 {id: 8456218226475281, url: '.....', address: 'old', symbol: '2345', fav: false},
 {id: 6759748921116029, url: '.....', address: 'new', symbol: '$B2345ROKE', fav: false}
];


const addr="new";
const list = bookmarks.filter(({address}) => address === addr);
let cnt = 0;
const show = () => {
  if (cnt >= list.length) return; // stop the listing
  console.log(list[cnt].symbol);
  cnt++;
  setTimeout(show,2000); // next one
};
show()

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!