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

414
Vistas
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 Respuestas
Responde la pregunta

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 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