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


Solution 1:[1]

let listofRandom = [5, 1, 7];
listofRandom.map((num) => {
  setInterval(function() {
    console.log(num);
  }, num * 1000)});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kyriazis