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

146
Vistas
How to console each value of number array with setInterval of the value as seconds Reactjs

let listofRandom = [ ]

console each value I push into that array, with certain time intervals

For example: let listofRandom = [5, 1, 7 ]

Here 1st value is 5 which means it has to console the "5" for every 5 seconds and the next value is 1 has to console the "1" for every 1 second and then console "7" for every 7 seconds.

let listofRandom = [];
let generatedValues = '';

const addValue = () => {
let value = Math.floor(Math.random() * 9) + 1;
listofRandom.push(value);
console.log(listofRandom)
};

  listofRandom.map((num) => {
return setInterval(function () {
  generatedValue = generatedValue + num.toString(); 
  console.log(generatedValue); 
}, num * 1000);
});
return(
<button onclick="addValue()">Add Value To Array </button>)
 
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

let listofRandom = [5, 1, 7];
listofRandom.map((num) => {
  setInterval(function() {
    console.log(num);
  }, num * 1000)});
about 4 years ago · Juan Pablo Isaza Denunciar

0

    const [values, setValues] = useState([1, 5, 7]);

    const [count, setCount] = useState(0);

    useEffect(() => {
        let counter = count;
        const interval = setInterval(() => {
            if (counter >= values.length) {
                clearInterval(interval);
            } else {
                console.log(values[counter]);
                setCount((count) => count + 1);
                counter++;
            }
        }, values[counter] * 1000);
        return () => clearInterval(interval);
    }, [count]);
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