javascript的console.log()用法

时间:2021-01-13 14:47:18

1、javascript的console.log()用法

2、源码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
        <script type="text/javascript">
            //变量
            var i = 'I am a string';
            console.log('变量:', i);
            
            //数组
            var arr = [1, 2, 3, 4, 5];
            console.log('数组:', arr);
            
            //对象
            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('对象:', obj1);
            //对象数组
            var objArr1 = [obj1, obj2, obj3];
            var objArr2 = [[obj1], [obj2], [obj3]];
            
            console.log('对象数组1:', objArr1);
            console.log('对象数组1:', objArr2);
        </script>
    </head>
    <body>
    </body>
</html>

3、生成的结果(在firebug中查看的结果)

变量: I am a string
NewFile.html (第 10 行)
数组: [1,2,3,4,5]
NewFile.html (第 14 行)
对象: Object{ key1="value1",key2="value2",key3="value3"}
NewFile.html (第 33 行)