Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
How to get and store the console logged value in javascript

I am trying to get the console logged value

here is the code,

console.log('sample output');
var logBackup = console.log;
var logMessages = [];

console.log = function () {
  logMessages.push.apply(logMessages, arguments);
  logBackup.apply(console, arguments);
};

console.log('logged values here', logMessages);

but it's returning a recursion empty arrays,

enter image description here

is there any way to get the console logged value and display that on webpage

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe something like this? Just a quick hack but the key is that I check that I don't add a reference of logMessages into logMessages itself, avoiding the circular reference.

console.log('sample output');
var logBackup = console.log;
var logMessages = [];

console.log = function (...argz) {
  pushArgz = argz.filter(a => a !== logMessages);
  logMessages.push(...pushArgz);
  logBackup.apply(console, argz);
};

console.log('logged values here', logMessages);
console.log('logged values here', logMessages);
console.log('logged values here', logMessages);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!