JavaScript's Console.log () usage//variables
var i = ' I am a string ';
Console.log (' variable: ', i);
Array
var arr = [1,2,3,4,5];
Console.log (' array: ', arr);
Object
var obj1 = {
Key1: ' value1 ',
Key2: ' value2 ',
Key3: ' Value3 '
};
var obj2 = {
Key6: ' Value4 ',
Key5: ' Value5 ',
Key4: ' Value6 '
};
var obj3 = {
Key9: ' Value7 ',
Key8: ' Value8 ',
Key7: ' Value9 '
};
Console.log (' object: ', obj1);
Object array
var objArr1 = [Obj1,obj2,obj3];
var objArr2 = [[Obj1],[obj2],[obj3]];
Console.log (' Object array 1: ', OBJARR1);
Console.log (' Object array 1: ', OBJARR2);
/*
Output:
Variable: I am a string
Array: [1, 2, 3, 4, 5]
Objects: Object {key1= "value1", key2= "value2", key3= "Value3"}
Object array 1:[object {key1= "value1", key2= "value2", key3= "Value3"}, Object {key6= "Value4", key5= "Value5", key4= "Value6"}, Object {key9= "Value7", key8= "Value8", key7= "Value9"}]
Object array 1:[[object {key1= "value1", key2= "value2", key3= "Value3"}], [object {key6= ' value4 ', key5= ' value5 ', key4= ' Value6 '}] , [Object {key9= "Value7", key8= "Value8", key7= "Value9"}]]
*/
Xmbuxi
[Email protected]
Reference address
The usefulness of Console.log ()It's mostly handy for your modal JavaScript, and you can see what you're outputting in the page.
His advantages compared to alert are:
He can see the structure of things, if it is alert, fade out an object is [Object Object], but the console can see the contents of the object.
Console does not interrupt the operation of your page, if you use alert to bounce out the content, then the page is dead, but the console output after your page can be normal operation.
The console is very informative and you can enter console in the console and you will see:
Usage of console in JavaScript