0

I am running a file like so:

for (let i = 100; i--){
  console.log(i);
}

How can I make this console each number in the same place:

console.log(99 --> changes to 98, 97, 96)

Instead of :

console.log(99);
console.log(98);
console.log(97);
...
Joe
  • 41,484
  • 20
  • 104
  • 125
Taylor Austin
  • 5,407
  • 15
  • 58
  • 103
  • 1
    If this is browser-side (vs. server-side Node.js), you can't. `console.log` will always append a newline. – Joe May 17 '18 at 19:45
  • 1
    This is server side , node is server side – Taylor Austin May 17 '18 at 19:46
  • 2
    If, however, this is server-side, you can use `process.stdout.write` instead of `console`. See [this answer](https://stackoverflow.com/a/9628935/1810460) – Hamms May 17 '18 at 19:46
  • https://stackoverflow.com/questions/9006988/node-js-on-windows-how-to-clear-console – epascarello May 17 '18 at 19:48
  • @Hamms Since I said this was in node which is server-side code, put your code as an answer because it worked. – Taylor Austin May 17 '18 at 20:04
  • @TaylorAustin next time i'd tag this Q as node.js... and as such this should be closed as a dup of https://stackoverflow.com/a/9628935 – Joe May 17 '18 at 20:46

1 Answers1

1

You can useconsole.log('\033[2J'); after each console.log() call.

AndrejH
  • 2,028
  • 1
  • 11
  • 23