M -
M -

Reputation: 28472

Is there a way for console.log() to update a line instead of appending new ones?

If I want to track a variable that updates very frequently, I can do console.log(myVar);, which appends a line at the bottom of the console:

enter image description here

Is there a way to replace the value of the last line, instead of appending a new line at the bottom?

enter image description here

This would be super helpful, because then I could look at previous logs without having them get scrolled out of view at the top.

I've tried the following:

console.clear();
console.log(myObject);
console.log(myVar);

But this doesn't work because re-logging objects collapses them, plus it flickers too much in Chrome. I read the MDN documentation on the console, and even though it has lots of neat features, I couldn't figure out how to just rewrite a single line. I've seen it being done in terminals/command prompts, does the browser console have that capability?

Upvotes: 6

Views: 4788

Answers (1)

Martin
Martin

Reputation: 2673

Google chrome has now in console ability to "Create live expression"

enter image description here

Upvotes: 8

Related Questions