LoginSignup
1
0

More than 5 years have passed since last update.

window.consoleの使い方

Last updated at Posted at 2015-03-26

logを出力する

js
var str = "文字列" ,
num = 666 ,
flo = 1.7320508075 ,
url =  'http://google.com/';

console.log('Stringの出力 : %s', str);
console.log('Numberの出力 : %i', num); // %dも利用可
console.log('Floatの出力  : %f', flo);
console.log('URLの出力  : %o', url);
console.log('複数出力 : %s %d %f',str,num,flo);

アイコン付きで出力する

js
console.info('information');
console.warn('warning');
console.error('error');

配列を表示させる

js
console.table([[1,2,3], [2,3,4]]);

オブジェクトを表示させる

javascript
console.dir({js:'javascript'});

グルーピング

js
console.group('GROUP1');
console.log('フルーツ');
console.dir({'apple': 10,'orange': 5});
console.groupEnd('GROUP1');

console.group('First group');
console.log('a');
console.log('b');
console.log('c');
console.groupEnd();
console.group('Second group');
console.log('1');
console.log('2');
console.log('3');
console.group('Embeded subgroup');
console.log('α');
console.log('β');
console.log('γ');
console.groupEnd(); // For the "Embeded subgroup" 
console.groupEnd(); // For the "Second group"

traceする

javascript
function parentFunc() {
    function childFunc() {
        function targetFunc() {     
            console.trace();
        }
        targetFunc();
    }
    childFunc();
} 
parentFunc();

経過時間を計測する

javascript
function workFunc() {
    var ret = 0;
    for (var i = 0; i < 999; i++) {
        ret += i;
    }

    console.log(ret);
}

console.time('Time'); 
workFunc();
console.timeEnd('Time');
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0