Home > Web Front-end > JS Tutorial > body text

Detailed explanation of js console.log printing object and array usage

高洛峰
Release: 2017-02-03 14:42:05
Original
1204 people have browsed it

The example in this article describes the usage of js console.log printing objects and arrays. Share it with everyone for your reference, the details are as follows:

What is console.log? It is actually just a function for printing js arrays and objects, just like PHP's print_r, var_dump. There is nothing much to say about the console.log function itself. This blog will tell you how to use this function. Before talking about this function, I think what everyone uses most to view js output is alert, but alert can only play string or int

1. Test file test.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>console.log test</title>
</head>
<script type="text/javascript">
var testobj =
  {
    &#39;id&#39;: 1,
    &#39;content&#39;: &#39;test&#39;,
    &#39;firstname&#39;: function() {
      document.getElementById(&#39;firstname&#39;).value = "zhang";
    },
    &#39;lastname&#39;: function() {
      document.getElementById(&#39;lastname&#39;).value = "ying";
    }
  };
<!-- 打印对像 -->
  console.log(testobj);
</script>
<body>
   <input type="text" id=&#39;firstname&#39; name="firstname" value=&#39;&#39;>
   <input type="text" id=&#39;lastname&#39; name=&#39;lastname&#39; value=&#39;&#39;>
</body>
</html>
Copy after login

2. Chrome development tools view js objects

js console.log打印对像与数组用法详解

console chrome

Now when I use chrome developer tools and firebug, they are half and half. Chrome developer tools also have a function that firebug does not have.

The console can run js. If the page is an iframe, firebug can only run on the parent, and chrome can select the page inside to execute. , if the picture below

js console.log打印对像与数组用法详解

chrome iframe console

3. Firebug view js object

js console.log打印对像与数组用法详解

firebug console

I hope this article will be helpful to everyone in JavaScript programming.

For more js console.log printing objects and array usage details, please pay attention to the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!