Question

is there a way to make a function that runs console.log for a string of variables. running once for the name of the variable name and once to show its val

function multilog(text){
    var text=text.split(",")
    for(i=0;i<text.length;i++){
        console.log(text[i]+': ')
        console.log(JSON.stringify(text[i]));
    }
}
multilog('number_words,number_paragraphs,relatedwords');

an example of desired output

number_words: 1 number_paragraphs: 2 relatedwords: [example example example]

Was it helpful?

Solution 2

console.multilog = function(str){
    var toLog = str.split(',');
    for (var i = 0, len = toLog.length; i < len; i++){
    console.log(toLog[i] + ' =>');
    console.log(eval(toLog[i]));
    }
};

OTHER TIPS

var logNumber = 0;

// The _log() will be a global function so you could access it from any place in the code.
// You can pass parameters like : _log( 'Something', 'Anything', '...', '...' ) 
_log = function () {
    console.log( '========= Log number : ' + logNumber + '. =========' )
    for( var i = 0, l = arguments.length; i < l; i ++ ) {
        console.log( arguments[ i ] );
    }
    console.log( '====== End of log number: ' + logNumber + '. ======' )
    logNumber ++;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top