-3

I am trying to log some details to browser console. I want to prefix each statement with current data and time.

e.g. 02/02/14 14:37 : some data

I tried it by creating new Date object. But this turns into creating so many Date objects.

What is the efficient way to do this in javascript?

Thanks.

Foreever
  • 7,099
  • 8
  • 53
  • 55
sonam
  • 875
  • 2
  • 18
  • 37

1 Answers1

3

You could wrap the console.log method into a function

function log(txt) {
    console.log(new Date().toString(), txt);
}

You can always break it down further to only get the bits and pieces you want.

Then use:

log('test');