Given a range, if you want to print numbers in that range at an interval of every 1 second using setTimeout &setInterval then check below code
const printNumbers = (from = 1, to) => {
//using setTimeout
for (let i = from; i <= to; i++) {
setTimeout(() => {
console.log(i);
}, i * 1000);
}
};
const printNumbers = (from = 1, to) => {
//using setInterval
for (let i = from; i <= to; i++) {
let interVal = setInterval(function () {
console.log(i);
}, i * 1000);
setTimeout(() => {
clearInterval(interVal);
}, i * 1000);
}
};
printNumbers(1, 10);